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

From CodeCodex

PHP[edit]

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

<?php

/*
 *  Database connection code goes here.
 */

// Connect to the database
db_connect();

// 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;

?>