#1
  1. No Profile Picture
    frequent PHP idiot
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    354
    Rep Power
    12

    Grouping row results by a category


    I'm interested in pulling all the rows and then grouping them under a head of each client name. I'm having trouble figuring how to only list a client name once and then group each results under that.

    PHP Code:
    $users DB::query("SELECT * FROM users ORDER BY client_name"); 
    How would I do this?
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,186
    Rep Power
    9398
    While you're reading the results, keep track of the previous client name. Start a new "group" whenever it changes.
    Code:
    previous client = empty
    for each user {
        if current client != previous client {
            if the previous client isn't empty and you need to "close" groups {
                close the previous group
            }
            start a new group for this client
        }
        display the user
        previous client = current client
    }
    if you need to "close" groups {
        close the previous and last group
    }
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Dec 2004
    Posts
    3,008
    Rep Power
    376
    i used to use this and correct me if i am wrong... it "might" be quicker than having to use if all the time..

    for each row {
    array['client_name'][] = //whatever info you need.. or if you need more than one info
    array['client_name']['userid']['name'] = //
    array['client_name']['userid']['date_birth'] = //
    }

    // do a foreach loop..
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    1
    Rep Power
    0

    Grouping row results by a category


    I have a column with 250 different bits of data ranging from numbers 1-6. When I try to make that column into a pie chart the numbers dont group together. How do I do it so that there are 6 different categories on the pie chart (one for each individual number) instead of 250 sections on the pie chart.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Dec 2004
    Posts
    3,008
    Rep Power
    376
    need info with regards to field names, and what code you have done so far

IMN logo majestic logo threadwatch logo seochat tools logo