matt121400 Posted April 30, 2009 Share Posted April 30, 2009 ok i know how to connect to the mysql database and all that jazz. The question i have is lets say i have 2 columns: 1)city(ex. baltimore) 2)food(ex. cookies) there are several cities in the database and they reappear all the time, same with the food column what i want to show is a list of cities where lets say the food 'cookies' appears most often and ordered from most to least, and also wondering how i can have it only show all the cities with at least 5 occurences of 'cookies' in the food column. Link to comment https://forums.phpfreaks.com/topic/156338-php-display-mysql-problem/ Share on other sites More sharing options...
9three Posted April 30, 2009 Share Posted April 30, 2009 In your query use ASC and LIMIT 5 limit 5 will give you row 0, 1, 2, 3, 4 Link to comment https://forums.phpfreaks.com/topic/156338-php-display-mysql-problem/#findComment-823141 Share on other sites More sharing options...
matt121400 Posted May 1, 2009 Author Share Posted May 1, 2009 sorry i think i may have confused you i meant to have it show all the citys where in the column food cookie has appeared atleast 5 times Link to comment https://forums.phpfreaks.com/topic/156338-php-display-mysql-problem/#findComment-823144 Share on other sites More sharing options...
sasa Posted May 1, 2009 Share Posted May 1, 2009 SELECT city, COUNT(*) AS num FROM table_name WHERE food='cookies' GROUP BY city HAVING num>4 ORDER BY num DESC Link to comment https://forums.phpfreaks.com/topic/156338-php-display-mysql-problem/#findComment-823280 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.