To get number of rows in result set there are two ways:
Is to use query to get count
$query=\"Select count(*) as count from some_table where type=
If your goal is to actually count the rows, use COUNT(*)
. num_rows
is ordinarily (in my experience) only used to confirm that more than zero rows were returned and continue on in that case. It will probably take MySQL longer to read out many selected rows compared to the aggregation on COUNT
too even if the query itself takes the same amount of time.