Php Sql Result


 

Php Sql Result

This example illustrates how to display result on the browser and how to use the result in the php application.

This example illustrates how to display result on the browser and how to use the result in the php application.

Php Sql Result

This example illustrates how to display result on the browser and how to use the result in the php application.

In this example we create a select query by using mysql_query method and stored it in the result variable which indicate by $ (dollar sign). Here we display the result in form of html table but as per your requirement we display the table in normal form by using like:

while($row = mysql_fetch_array($result)){
        echo $row['username'] . " " . $row['email'];
        echo "<br>";
}

 

Table: users

 

Source Code of sql_result.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 users");

  echo "<table border='1'>
  <tr>
    <th>User Name</th>
    <th>Email Address</th>
  </tr>";

  while($row = mysql_fetch_array($result)){
    echo "<tr>";
    echo "<td>" . $row['username'] "</td>";
    echo "<td>" . $row['email'] "</td>";
    echo "</tr>";
  }
  echo "</table>";

  mysql_close($con);
?>

Download Source Code

 

Output:

Ads