#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    36
    Rep Power
    15
    I want to output mysql data by groups (states). However each time php/mysql comes to a new state in the results I want it to print the state name before putting the results. Does php have some sort of memory function to recognize when the state has changed?

    ie
    Output:
    Alabama
    dataalabama1
    dataalabama2
    dataalabama3...until new state then it puts
    Alaska
    dataalaska1
    dataalaska2
    etc.until new state. then
    NewState
    datanewstate...etc

    Thanks
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    Yes, they're called variables.

    Assign the state to a variable and then compare it to each record as you retrieve them. If it's different, change the temp variable to the new state and print out a header line.

    Something like:

    $tempstate="";
    while ($data=mysql_fetch_row($result))
    {
    if ($tempstate!=$data[state])
    {
    $tempstate=$data[state]);
    print "<P><EM>$tempstate</EM><BR>";
    }
    // print record info
    }

Similar Threads

  1. Can anyone help with mysql query and results?
    By msmith29063 in forum MySQL Help
    Replies: 3
    Last Post: February 8th, 2004, 04:43 AM
  2. Sorting MySql results by nearest to furthest away
    By highlander5430 in forum MySQL Help
    Replies: 7
    Last Post: January 25th, 2004, 02:40 PM
  3. Overwriting mysql query with the query results
    By onerandomday in forum PHP Development
    Replies: 1
    Last Post: January 14th, 2004, 05:45 AM
  4. mysql results into session array
    By TuxLives in forum PHP Development
    Replies: 10
    Last Post: January 6th, 2004, 02:09 PM
  5. PHP Code in mySQL results
    By NightShade737 in forum PHP Development
    Replies: 2
    Last Post: January 3rd, 2004, 11:53 AM

IMN logo majestic logo threadwatch logo seochat tools logo