SQL PHP HTML ASP JavaScript articles and free scripts to download
 
 

Finding total number of rows in a table

We can get the number of rows or records present in a table by using mysql_num_rows() function. This function is to be used along with mysql select query. We can add condition by using mysql where clause to the select query and get the conditional rows. This function is widely used in different php scripts and you can see the use of this function in PHP paging tutorial in our php tutorial section. Please note that this can't be used along with update, delete, insert commands, for this mysql_affected_rows is to be used. You can use count command also to read the number of records. Here is the sample code for mysql_num_rows()


Related Tutorial
SQL Count
SQL select
Number of Affected rows
PHP MySQL functions


$query = mysql_query("SELECT * FROM student");
$number=mysql_num_rows($query);
echo "Total records in Student table= ". $number;



Discuss this tutorial at forum

List of SQL Tutorials


 
Scripts
PHP
JavaScript
HOME
SQL Tutorial List
SQL (Home)
SQL Commands
AVG
Alter Table
Between
Count
Copy Table
Create Table
Delete
Distinct
Group by
Having
Insert
Inner Join
IN
Left join
Limit
Like
MAX
MIN
Order By
OR AND
Rand
Replace
Rename Table
Select Query
Sum
Union
Update
Where
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.