Fetch xth item from mysql_array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RayDube
    New Member
    • Dec 2007
    • 15

    Fetch xth item from mysql_array

    Hey gentlebeings,

    I'm pretty sure this is possible, just can't find the correct way to do it.

    I want to select the contents of my table of testimonials, and randomly display one of them on the screen.

    So the thinking we had over here was to count the number of rows and then select the xth row for display. We just weren't sure on the options available to us. :)

    One option was to count the rows, use that number for the basis for a random select (i.e. mt_rand(1,$num_ testimonials)) and select that row.

    Just not sure if that would work at all...

    If I recall correctly, fetching an associative array will allow us to move forward and backwards through it, so somehow this should be possible.

    I'm open to all suggestions, can't even think of a way to start this.

    Thanks,

    Ray
  • RayDube
    New Member
    • Dec 2007
    • 15

    #2
    Duh!

    Sorry people, the answer was so obvious it slapped us in the face!

    Code:
    SELECT column FROM table ORDER BY RAND() LIMIT 1
    Works like a charm!

    Ray

    (figures we should have just spoken to the sql guru rather than the php guru)

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      Glad you got that sorted.

      Comment

      Working...