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. Quote 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 Quote 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 Quote 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 Quote Link to comment https://forums.phpfreaks.com/topic/156338-php-display-mysql-problem/#findComment-823280 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.