Jump to content

[SOLVED] Count how many rows


clay1

Recommended Posts

I have a query which selects all the rows matching a market and then displays how many results there were

 

I need to be able to break that down to display how many total results, and how many were under a certain age

 

Do I need to do a separate select statement? Or can I use something like pg_num_rows to count how many are under age 25?

Link to comment
https://forums.phpfreaks.com/topic/174728-solved-count-how-many-rows/
Share on other sites

what does your code currently look like?

 

but you could just  iterate throughthe rows. While you iterate, you have several tests, and update several counters based on that test. for example

 

//sql stuff above
$arr = array();
$count = 0;
$count1 = 0;
$count2 = 0;
while($row = mysql_fetch_assoc($query)){
$count++;
if ($row['age'] < 25){
$count2++;
}
#etc
}

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.