How to display a result uptop if it has the value of one?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ajm113
    New Member
    • Jun 2007
    • 161

    #1

    How to display a result uptop if it has the value of one?

    Ok, how do I have it so the script will display a result with a value of lets say one in mysql up top of a while loop when it echoes out the results?
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, AJM.

    Do you want to output row numbers? Or are you trying to only display rows that have a certain value? Do you need to output a specific row ahead of all the others?

    Comment

    • Ajm113
      New Member
      • Jun 2007
      • 161

      #3
      I want to display a row with a value of 1 up top I guest...

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Heya, Ajm113.

        Originally posted by Ajm113
        I want to display a row with a value of 1 up top I guest...
        Alrightey. Probably the easiest way to do it is to create a variable to hold the top row. While you're fetching your MySQL results, check for the value that you want. If it matches, set the top variable to that row. Otherwise, add the row to your array as normal.

        Once you're done loading results, check for the top variable and output it.

        Expressed as code:
        [code=php]
        $data = array();
        while($row = mysql_fetch_ass oc($result)) {
        if($row['desiredField'] === 'desiredValue')
        $top = $row;
        else
        $data[] = $row;
        }

        if(isset($top))
        // Display the top row.

        // Display the other rows.
        [/code]

        If you want the top row to be featured, but still appear in the rest of the table, just remove the else.

        Comment

        • Ajm113
          New Member
          • Jun 2007
          • 161

          #5
          Thanks! :)

          P.S Sorry, if you seen that post report someone was messing around with my PC at the time.

          Comment

          • pbmods
            Recognized Expert Expert
            • Apr 2007
            • 5821

            #6
            Heya, Ajm.

            Originally posted by Ajm113
            Thanks! :)

            P.S Sorry, if you seen that post report someone was messing around with my PC at the time.
            No prob. Post back if you need anything.

            And yeah, I think that happened b/c the 'Report' and 'Reply' buttons are so close together. I've made a note of that for the future.

            Comment

            • Ajm113
              New Member
              • Jun 2007
              • 161

              #7
              Originally posted by pbmods
              Heya, Ajm.



              No prob. Post back if you need anything.

              And yeah, I think that happened b/c the 'Report' and 'Reply' buttons are so close together. I've made a note of that for the future.
              Its like having the self destruct button in a way right next to make coffee button with the same colors and look.

              Comment

              • pbmods
                Recognized Expert Expert
                • Apr 2007
                • 5821

                #8
                I've posted a suggestion to this effect here. Feel free to add your thoughts.

                Comment

                Working...