Home Tutorial Php Sql Php Sql Result

 
 

Php Sql Result
Posted on: December 10, 2010 at 12:00 AM
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:

Related Tags for Php Sql Result:


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.