Monday, 9 September 2013

List mysql data grouped together and show num_rows for each group

List mysql data grouped together and show num_rows for each group

i have this SQL Code that select rows from a table and groups them
together by the category column
echo '<strong>Categories</strong><br>';
$sql="SELECT * from tickets where deleted = '' and DAY(datetime) =
'04' and MONTH(datetime) = '".date("m")."' and YEAR(datetime) =
'".date("Y")."' group by category order by datetime ASC ";
$rs=mysql_query($sql,$conn);
while($result=mysql_fetch_array($rs))
{
echo $result["category"].' ('.mysql_num_rows($rs).')<br>';
}
when displaying the number of rows, its showing the same number on each one.
how can i make this display the correct number next to each 'category' ?

No comments:

Post a Comment