iceman023 Posted July 14, 2009 Share Posted July 14, 2009 I have a dropdown menu that sorts pictures by cities.. I want to use a function with the SQL COUNT to have a number of pictures next to the city before you click on the city so the user knows how many before hand. SELECT Count(City) FROM Photos WHERE City='Chicago' That works in PHP my admin but how do i turn it into a function and display the number.. Link to comment https://forums.phpfreaks.com/topic/165867-sql-count-function/ Share on other sites More sharing options...
ldougherty Posted July 14, 2009 Share Posted July 14, 2009 Rather then running a query for each individual city I'd suggest having one query and then run a while loop that populates an array. IE.. result = select Count(City) FROM Photos row = fetch row result $city = $row[city]; then have a case statement case philly phillycount++ etc etc. hope that makes sense.. Link to comment https://forums.phpfreaks.com/topic/165867-sql-count-function/#findComment-874909 Share on other sites More sharing options...
iceman023 Posted July 14, 2009 Author Share Posted July 14, 2009 How do you write the code for that though. I can only display a number in php myadmin.. $numresults = mysql_query(" SELECT Count(City) FROM Photos WHERE City='Chicago' "); echo ($numresults); "Resource id #4 " this is what happens If i do it the way you said how can you make an array and use it with ALL CSS dropdown Link to comment https://forums.phpfreaks.com/topic/165867-sql-count-function/#findComment-874914 Share on other sites More sharing options...
iceman023 Posted July 14, 2009 Author Share Posted July 14, 2009 $sql = mysql_query('SELECT Count(City)FROM Photos WHERE City=\'Chicago\''); $count = mysql_num_rows($sql); echo $count; this displays 1 when infact these 2?? Someone help please! Link to comment https://forums.phpfreaks.com/topic/165867-sql-count-function/#findComment-874931 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.