Hi,
I'm fairly new to PHP and mySQL and I'm trying to write some code to do the following:
1. I have a database called stories which has a field called citycode which relates to a table called city that has the city long name.
2. I want to select from stories and list out the cities, and number of stories in each city alphabetically.
3. I've written some code below that 'tries' to do this but doesn't output the cities alphabetically. They come out ordered by the citycode.
4. How can I do this?
Here's the code:
$result=mysql_query("SELECT citycode, count(citycode) as citycount FROM stories GROUP BY citycode");
while(list($citycode, $citycount) = mysql_fetch_row($result)) {
$result2 = mysql_query("SELECT cid, city FROM city WHERE $citycode=cid ORDER by city");
list($cid, $city) = mysql_fetch_row($result2);
echo "$city - $citycount";
}




Bookmarks