Home Tutorial Php Sql Php Sql Rows

 
 

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

Related Tags for Php Sql Rows:


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.