PHP SQL Output

Ads
 

PHP SQL Output

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

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:

Ads

Ads