Share on Google+Share on Google+

Php Sql Rows

Advertisement
This example illustrates how to fetch row of database table.

Php Sql Rows

 This example illustrates how to fetch row of database table.

In this example we create mysql query to select the column name email which id has 12 and fetched row value and display it on the browser.

 

 

Table: users

 

Source Code of sql_rows.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 id,email FROM users WHERE id = '12'");

  if (!$result) {
    echo 'Could not run query: ' . mysql_error();
    exit;
  }

  $row = mysql_fetch_row($result);
  echo "<b>ID: </b>";
  echo $row[0]."<br>";
  echo "<b>Email: </b>";
  echo $row[1];
?>

Download Source Code

 

Output:

Advertisements

Posted on: December 10, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial 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.