I need a bit of help, if anyone can help me.
I have been scratching my head for the last few hours. I am trying to list the Towns with the peoples names from my database. At present I am getting the town and only one name. I need to display all the names. Here is the output I recieve form my php page.
Brighton
Peter (2)
Newhaven
John (1)
Peacehaven
Paul (1)
In Newhaven I have at least another two names that should be displayed at the moment it is only showing John.
Here is my code, I hope someone can help me. Many thanks.
$query = "SELECT town, name,
count(name) AS cnt
FROM peopletbl GROUP BY town";
$res = mysql_query($query) or die(mysql_error());
if(mysql_num_rows($res) > 0) {
while($row=mysql_fetch_array($res)) { ?>
<? echo $row['town']; ?><br><? echo $row['name']; ?> (<? echo $row['cnt']; ?>)<br>
<br>
<? }
}
else {
echo "Nothing found"
} ?>
The output needs to be like this
Brighton
Peter (2)
Clare(1)
Newhaven
John (1)
David(1)
Robert(1)
Peacehaven
Paul (1)