Jump to content

Noob question - displaying count by group


melting_dog

Recommended Posts

Hi guys,

 

Sorry - I know this is a basic question but I've been out of the game for a year now and need to jog my memory.

 

I am trying to count the number of rows per group. e.g:

 

$sql =  "SELECT *, COUNT(id) FROM image GROUP BY city";

$result = mysql_query($sql);

$row = mysql_fetch_assoc($result);

 

echo $row['COUNT(id)'];

 

 

So if there are, for example, 5 New York's in the table, 3 London's and 2 Sydney's I want the echo to display 5, 3, 2

 

Should I use a loop for this?

 

Cheers

Link to comment
https://forums.phpfreaks.com/topic/249311-noob-question-displaying-count-by-group/
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.