[PHP 4, PHP 5]
mysql_num_rows — Get number of rows in result
Description
mysql_num_rows[resource $result
]: int|false
Parameters
result
The result resource that is being evaluated. This result comes from a call tomysql_query[].
Return Values
The number of rows in a result set on success or false
on failure.
Examples
Example
1 mysql_num_rows[] example
``
Notes
Note: If you use mysql_unbuffered_query[], mysql_num_rows[] will not return the correct value until all the rows in the result set have been retrieved.
Note: For backward compatibility, the following deprecated alias may be used: mysql_numrows[]
See Also
- mysql_affected_rows[] - Get number of affected rows in previous MySQL operation
- mysql_connect[] - Open a connection to a MySQL Server
- mysql_data_seek[] - Move internal result pointer
- mysql_select_db[] - Select a MySQL database
- mysql_query[] - Send a MySQL query
19 years ago
`Some user comments on this page, and some resources including the FAQ at :
suggest using count[*] to count the number of rows
This is not a particularly universal solution, and those who read these comments on this page should also be aware that
select count[] may not give correct results if you are using "group by" or "having" in your query, as count[] is an agregate function and resets eachtime a group-by column changes.
select sum[..] ... left join .. group by ... having ...
can be an alternative to sub-selects in mysql 3, and such queries cannot have the select fields replaced by count[*] to give good results, it just doesn't work.
Sam
`
19 years ago
`Re my last entry:
This seems the best workaround to get an 'ordinary' loop going, with possibility of altering output according to row number [eg laying out a schedule]
$rowno=mysql_num_rows[$result];
for [$i=0; $i