Home Sql Mysql-example PHP SQL Output



PHP SQL Output
Posted on: January 20, 2009 at 12:00 AM
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:

Related Tags for PHP SQL Output:
sqlcquerybrowseriooutputdisplayexecthisexerowrowsexampletoexecutionwseexamfetchwseilputsplulresultbrowseasmoutplaytrispeshowrateratescutxaxampsxesuspatisllmpletchetchstrutissthstdispfeetcetcpleplono


More Tutorials from this section

Ask Questions?    Discuss: PHP SQL Output  

Post your Comment


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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.