SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Threaded View

  1. #1
    SitePoint Member
    Join Date
    May 2001
    Location
    London
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php and mysql select question

    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";

    }
    Last edited by jetsetter; May 27, 2001 at 02:43.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •