I need to display 4 records randomly from my database everytime the page is refreshed. Has anybody any ideas of how to go about this?
Thanks
Try:
select * from mytable order by rand();
You could always load the results into an array.. and then pick a random value....
If you only want 4 records use:
SELECT * FROM table ORDER BY RAND() LIMIT 0,4
I am trying to do the same thing only a little different. Here is the query I am using...
SELECT ID FROM table WHERE PHOTO=1, SOLD=2 ORDER BY RAND() LIMIT 1;
and it will not work. Can someone please tell me the correct way to write this query??
Try
SELECT ID FROM table WHERE PHOTO=1 AND SOLD=2 ORDER BY RAND() LIMIT 0,1;
The earlier versions on MySQL did not support then rand() function... in which case you'll have to either upgrade.... or load the results into an array...