How to print out the number of total records from mysql on php?

Jonathan

New member
say i have a database with 1000 ids of students.. so i know i have 1000 records

now i want to show it on my record.php that i have how many records in database.
like Total numbers of student records: 1000
and the number should change as i add more records

how do i use php to echo out the highest # of id or the total # of ids as it would be the same.

if you can share me the complete coding, i'd be very grateful.. thank you.
 
Simply echoing the highest ID is not an accurate count. If you were to delete any students in the table, the highest ID would still be the same (unless you set up the table otherwise). An easy, although somewhat brute force way, of doing this would be:

$res = mysql_query("SELECT * FROM yourTable");
$numberOfRecords = mysql_num_rows($res);

Not the most elegant, but it works.
 
Back
Top