Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

MySQL & PHP quick question....

  • 09-03-2007 06:18PM
    #1
    Registered Users, Registered Users 2 Posts: 2,835 ✭✭✭


    Hey Lads,

    I'm getting a result back from the DB using

    $result = mysql_query($search);

    what i'm asking is if there is any way to search through the rows of results you get from this query so that i can sort them...

    i want to put them into a table with a colour coded background. i can do that no probs, but i want to have results of the same type in order

    e.g. say these are the result rows i get from the query
    id    -   name    -     position
    
    1    -    john     -     Manager
    2    -   michael  -     Supervisor
    3    -   sean     -     Clerk
    4    -   shane    -     Manager
    5    -   fred      -      Supervisor
    6    -   Steve   -      Manager
    

    can i search the rows to display the managers first, colour code them in a table, then display the clerks, colour code them and then the supervisors and colour code them?

    Unfortunately i cant use ORDER BY in the query as they are strings not in alphabetical order.

    Can anyone help me out?


Comments

  • Moderators, Politics Moderators, Paid Member Posts: 44,085 Mod ✭✭✭✭Seth Brundle


    Can you add another field to the table containing a number 1,2 or 3 depending on their role and sort that way - shouldn't take long?


  • Registered Users, Registered Users 2 Posts: 2,835 ✭✭✭StickyMcGinty


    yea trying to find a workaround like that alright, cheers


  • Closed Accounts Posts: 2,349 ✭✭✭nobodythere


    What you could do is do three seperate queries and print it out accordingly.

    The slightly more complex way would be like so (this code prob has a million errors):
    $result = mysql_query("SELECT * from dbname ORDER BY position;");
    
    while($row=mysql_fetch_array($result))
    {
      if($row['position'] == 'Manager')
      {
         ...code for this bit
      }
      else if($row['position'] == 'Supervisor')
      {
         ...code for this bit
      }
      else if($row['position'] == 'blahblahblah')
      {
         ...code for this bit
      }
    }
    
    


  • Registered Users, Registered Users 2 Posts: 2,835 ✭✭✭StickyMcGinty


    i ended up sending the query off 3 times and passing it through a function to colour code it, thanks for the help anyway lads!


Advertisement