Friday, December 20, 2013

Tute 9: Show Data in Website From Mysql Database

Last tutorial we know about connect database to website. And connect home page to php file. Now we will see our data in our homepage from mysql database

Open the notepad++ software and write this code in index.php file. We write this code into the <?php ?> code.

--------------------------------------------------------------------------------------------
<?php
 require 'connect.inc.php';

$query= "SELECT `id`, `heading`, `details`, `category` FROM tute ";
$query_run=mysql_query($query);
?>
-------------------------------------------------------------------------------------------

Query for show data form mysql database


First line selects id, heading, details and category from tute from mysql database.

Second  line make query in selected item.

After that we write this code into the body.  Delete the "<h3>This is the left con</h3>" and write this code.

--------------------------------------------------------------------------------------------
<div id="body-con-l">
       <?php
              while ($query_row=mysql_fetch_assoc($query_run)){
              $heading=$query_row['heading'];
              echo $heading. '<br>';
              }
       ?>
</div>
--------------------------------------------------------------------------------------------


While loop and data showing code

Here we take while loop and '$heading'  variable. Then published the '$heading' and take <br> in every heading.

Now we save the file (ctrl+S). Go to the Google Chrome and open localhost/tute/index.php tab and refresh the page.

We see our all headline show in our home page who wrote in our database!

Show data in home page


If not see, check php code in index.php file.

No comments :

Post a Comment