PHP SQL Output

This example illustrates how to display the output fetched as a result of Sql query execution on the browser.

Ads

PHP SQL Output

     

This example illustrates how to display the output fetched as a result of Sql query execution on the browser.

After executing any sql query, you may need to show the output to the console or web page of the application. In the example below, we have created sql_output.php where a sql query is executed. Let's see how the output is displayed.

Source Code of sql_output.php 

<?php
  $con = mysql_connect("localhost","root","root");
  if (!$con) {
  die('Could not connect: ' . mysql_error());
  }

  mysql_select_db("test", $con);
  $result = mysql_query("SELECT * FROM employee LIMIT 0,5");
  echo "<b>Output Display in Table formate and php formate</b><br>";
  echo "<table border='1'>
  <tr>
  <th>ID</th>
  <th>Name</th>
  <th>Designation</th>
  <th>Salary</th>
  </tr>";
  while ($row = mysql_fetch_array($result)) {
  echo "<tr>";
  echo "<td>" . $row['id'] . "</td>";
  echo "<td>" . $row['name'] . "</td>";
  echo "<td>" . $row['designation'] . "</td>";
  echo "<td>" . $row['salary'] . "</td>";
  echo "</tr>";

  echo $row['id']." ".$row['name']." ".$row['designation']." ".$row['salary']."<br>";
  }
  echo "</table>";
  
  mysql_close($con);
?>

Download Source Code

 

Output:

Advertisements

Share on Google+Share on Google+

PHP SQL Output

Posted on: January 20, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: PHP SQL Output  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads