Results 1 to 5 of 5

Thread: grouping people

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Location
    Canada
    Posts
    75

    grouping people

    This is kind of hard to explain what i mean but here goes....

    i have a table with a number of people, similar to an address book... i would like to sort them alphabetically by name, grouped by the city they live in but i would like the output to be like so in the html

    CITY #1 - New york

    Person #1's detail - from new york
    Person #3's detail - from new york

    CITY #2 - LA

    Person #2's detail - from LA

    CITY #3 - Chicago

    Person #3's detail - from Chicago

    - now i already know how to get information from the database and what not, and i know the html for it, but what i cant figure out is how do i have it spit out each City and put the people under that city that live there

    Hope this makes some sense

  2. #2
    Member
    Join Date
    Apr 2002
    Posts
    52
    i didn't really understand your problem, but may be the SQL SELECT clause "GROUP BY" is what you need?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Location
    Canada
    Posts
    75
    not really because i want to actually OUTPUT the group name...i think i could do a group by and then do an if statement to see if its changed, but i'm not having much luck.

  4. #4
    scoutt
    Guest
    you can do 2 queries, as that might be the best bet.

    PHP Code:
    $sql mysql_query("select distinct state from table");
       while(
    $row mysql_fetch_array($sql)){
                 
    $sql2 mysql_query("select name from table where state = '".$row["state"]."' ");
                      while(
    $row2 mysql_fetch_array($sql2)){
                               
    //get fileds here and display
                      
    }
         } 
    something like that

  5. #5
    Fanatic Member ubunreal69's Avatar
    Join Date
    Apr 2001
    Location
    Morayfield, Australia
    Posts
    609
    wont it work if you sort the names then grou them by location ?

Posting Permissions

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



Click Here to Expand Forum to Full Width