Home Tutorial Php Sql Php Sql Result

 
 

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

Advertisement

Related Tags for Php Sql Result:


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: December 10, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com