Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select Random Record

Status
Not open for further replies.

alsaffar

Programmer
Joined
Oct 25, 2001
Messages
165
Location
KW
Hi there,

I want to select one record randomly, how can I acheive my goal?

Please help.
 
When you are saying "record", what do you mean?

If you meand a record from a database query:
1. issue the query and get the resource identifier
2. ascertain the number of records in the set.
3. use the rand() function to get a random number between 0 and the number of records -1
4. in MySQL e.g. use mysql_data_seek() to point to the random record.
5. get the data, example: mysql_fetch_array() or similar command.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top