How can i get the number of rows like mysql_num_rows
but without having a mysql resource to work from, because i don't know the future scale of my webapp and it could take an hour just to get the number of rows ;)
thanks!
How can i get the number of rows like mysql_num_rows
but without having a mysql resource to work from, because i don't know the future scale of my webapp and it could take an hour just to get the number of rows ;)
thanks!
SELECT COUNT(*) FROM table WHERE ...
See http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_count for differences between COUNT(*) and COUNT(id)
Make an SQL query with COUNT, e.g.:
SELECT COUNT(id) FROM table
SELECT COUNT(*) AS num_rows FROM tblName;
- and just retrieve num_rows
column from that statement.
Just in case you have a LIMIT clause in your "actual" sql query and want to know the toal number of items (e.g. when doing some kind of pagination) you might also be interested in SQL_CALC_FOUND_ROWS and FOUND_ROWS()
SELECT COUNT(*) AS number FROM table
Will return 1 row with a field called number which holds the number of rows in the table.