Home Sql Mysql-example PHP SQL Output
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

PHP SQL Output

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

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

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: January 20, 2009

Ask Questions?    Discuss: PHP SQL Output  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com