I've got a mysql table of 'events' with columns for 'category' and 'visited'. There's 3 categories an event can fall under. 'visited' counts how many times the event's page has been visited. I want the top two visited events from each of the 3 categories.
Here is an example table
id category visited
32 1 23
33 2 12
34 3 42
35 1 53
36 2 24
37 3 84
38 1 12
39 2 75
40 3 22
I need to display these rows in this order (id=): 35, 32, 39, 36, 37, 34. The code I have returns only 1 row from each category, and I believe is strictly limited to returning 1 row (I didn't write it.):
$categories=mysql_query("select distinct category from events");
while($row_cat=mysql_fetch_array($categories)){
$row=mysql_fetch_array(mysql_query("select * from events where category='".$row_cat['category']."' order by visited desc"));
echo $row['id'].", ";
}
That code displays: 35, 39, 37,
I feel as though the answer may be extremely simple, yet it is still eluding me. Thanks, in advance, for your help.