Count and display the number of rows in a mysql database table

From CodeCodex


This code will count the number of rows (entries / records) in a MySQL database table and then display it using echo on the screen.


 *  Database connection code goes here.

// Connect to the database

// Query the database and get the count
$result = mysql_query("SELECT * FROM tablename");
$num_rows = mysql_num_rows($result);

// Display the results
echo $num_rows;