Jump to content

Random Selection

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
dirkfirst

dirkfirst

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 354 posts
From a MySQL database how can I randomly selected the data I use with mysql_query($query)?

I think that creating an array and using the rand() function is my only choice. This takes a lot of resources when I'm pulling 10,000 rows. Any Ideas?

#2
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
you might be able to do this with a UNION

#3
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Just use the rand() function of MySQL.

SELECT * FROM tbl ORDER BY RAND() LIMIT 1;


#4
sfod_d223

sfod_d223

    Newbie

  • Members
  • Pip
  • 6 posts
I don't know if I'm asking this in the right room but here it goes. Where do I put a random function If I am trying to make random links for articles on homepage show up in different areas.

#5
Guest_Jordan_*

Guest_Jordan_*
  • Guests
If you want it on your homepage put it on your homepage. Are you using the mysql random function from above?

#6
dirkfirst

dirkfirst

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 354 posts

Jordan said:

Just use the rand() function of MySQL.


SELECT * FROM tbl ORDER BY RAND() LIMIT 1;



Thanks, works perfect.