July 30th, 2000, 08:44 AM
I'm using PHP3, does anyone know how I can pull a random row from a mySQL table?
PS - Can you please give me code, not just tell me what to do as I am a beginner!
July 30th, 2000, 09:53 AM
Just check the mysql version .... the latest version has this feature ....
use can use :
select * from tablename order by rand()
But if the above doesn't work then the version of mysql doesn't have the random feature .... there is another way around it
firstly u have to have an auto increment column (won't work if u dont) .. say its called ID. Then the sql statement u would use would be:
select *, ID*0+rand() as rand_col from tablename order by rand_col
July 30th, 2000, 09:59 AM
I've just worked it out:
1) Find out how many results = x
2) Get random number between 1 and x
3) Select from db where id = x
July 30th, 2000, 02:05 PM
No, looks like your way is better!!!