Possible Duplicate:
How can I count the numbers of rows that a mysql query returned?
To get the length of the return of a mysql result, I am using:
$counter=0;
while($row = mysql_fetch_array($mysqlqueryresult)){
$counter++;
}
echo $counter;
Is there a better way to get the number of rows returned by mysql?
Note - Not allowed to use COUNT in the mysql or any mysql tricks, only php on the mysql output as here. So starting point is a mysql returned thing of $mysqlqueryresult;
which itself is the result of a basic SELECT
query.
Use mysql_num_rows
.
$counter = mysql_num_rows($mysqlqueryresult);
If you've updated the table, the number of affected rows is given by mysql_affected_rows
.
mysql_num_rows() is the function you're looking for.
edit. I arrived too late. ;)
you Can use mysql_num_rows() routine .
$counter = mysql_num_rows($mysqlqueryresult);
Well, just for the method's sake (although mysql_num_rows()
is the preferred method), a pure php one without using a loop:
count($mysql_fetch_array($mysqlqueryresult));
(or am I completely mistaken?)