Select data from mysql database with PHP



User Rating:  / 0
PoorBest 
Details

How to select data from mysql database with php :

1. Make connection to mysql

2. Execute query

3. Write results to page 

Example : 

View source
 
<?php
 
 
// www.developerpages.gr
 
 
$con = mysql_connect("localhost","root","12345");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 
mysql_select_db("test_db"$con);
 
$result = mysql_query("SELECT * from example_table");
 
 
echo " border='1'>
 
 
<tr>
<th>id</th>
<th>Firstname</th>
<th>Lastname</th>
</tr>";
 
while($row = mysql_fetch_array($result))
  {
  echo "";
  echo "" . $row['id'] . "";
  echo "" . $row['FirstName'] . "";
  echo "" . $row['LastName'] . "";
  echo "";
  }
 
mysql_close($con);
?>

and the output is :


You have no rights to post comments

   

Login  

   

     

© Developerpages