...

View Full Version : How many rows in the db?



zonkd
01-05-2006, 04:20 PM
If I use $num = mysql_num_rows ($result); to show the results from the db, the figure I get is decided by the limit I have set in the mysql SELECT query.

Is there another way to show how many records exists in the table, please? I mean, the total number of files in the db regardless of how may I draw out?

devinemke
01-05-2006, 04:37 PM
SELECT COUNT(*) FROM table

Kid Charming
01-05-2006, 05:18 PM
You'll need to run a separate query for the total results, but the FOUND_ROWS() (http://dev.mysql.com/doc/refman/5.0/en/information-functions.html) function is an efficient way to do it:



//query 1
SELECT
SQL_CALC_FOUND_ROWS
col1
,col2
,col3
FROM
table
WHERE
foo = 'bar'
LIMIT 5;

//query 2
SELECT FOUND_ROWS();

VBAssassin
01-05-2006, 09:51 PM
This is what i do when ever i need total rows (records):


$total_rows = mysql_result(mysql_query("SELECT COUNT(*) As num FROM table"), 0);

Its the same method that the phpMyAdmin uses to show you the total records :thumbsup:

zonkd
01-06-2006, 08:45 AM
Hi devinemke, Kid Charming and VBAssassin

Many thanks for that, and three excellent ways to do it. Very grateful, gentlemen.

Cheers paul :thumbsup:

VBAssassin
01-06-2006, 09:23 PM
Hi devinemke, Kid Charming and VBAssassin

Many thanks for that, and three excellent ways to do it. Very grateful, gentlemen.

Cheers paul :thumbsup:

No problem mate, im here to help.. as long as i get helped in return when i need it lol.

Best regards,
scott



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum