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=
count is much more efficient both performance wise and memory wise as you're not having to retrieve so much data from the database server. If you count by a single column such as a unique id then you can get it a little more efficient