Php Sql Rows


 

Php Sql Rows

This example illustrates how to fetch row of database table.

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:

Ads