Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi all! We have been experiencing an issue on site where threads have been missing the latest postings. The platform host Vanilla are working on this issue. A workaround that has been used by some is to navigate back from 1 to 10+ pages to re-sync the thread and this will then show the latest posts. Thanks, Mike.
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

MySQL & PHP quick question....

  • 09-03-2007 6: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 Posts: 40,287 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