Jump to content

SQL Count Function


iceman023

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.