Home Tutorial Php Sql Php Sql Number of Rows

 
 

Share on Google+Share on Google+
Php Sql Number of Rows
Posted on: December 10, 2010 at 12:00 AM
Advertisement
This example illustrates how to count the rows of the table.

Php Sql Number of Rows

 This example illustrates how to count the rows of the table.

As per the previous example we create a php page to find the number of rows of the table. To find the number of the rows we use the mysql_num_rows method.

 

Table: users

 

Source Code of sql_num_rows.php 

<?php
  $con = mysql_connect('localhost','root','root');
  if (!$con) {
    die('Could not connect: ' . mysql_error());
  }
  mysql_select_db("test", $con);

  $sql = "SELECT * from users";

  $res = mysql_query($sql);

  if (!$res) {
    print("SQL statement failed with error:\n");
    print(mysql_error($con));
  else {
    $number_of_rows = mysql_num_rows($res);
    print("$number_of_rows rows found");
  }  
  mysql_close($con);
?>
Download Source Code

 

Output:

Advertisement

Related Tags for Php Sql Number of Rows:


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