Which way to count a number of rows should be faster in MySQL?
SELECT COUNT(1) FROM TABLE_NAME
When you COUNT(1) it takes in count column indexes, so it will be the best result. Mysql engine actually stores row count, it doesn’t count all rows each time you try to count all rows.
here is the codes you can use it in a script to echo the count
$counter = mysql_query(“SELECT COUNT(*) AS id FROM table_name”);
$num = mysql_fetch_array($counter);
$count = $num["id"];