Page 1 of 1

DB image randomizer

Posted: Thu Jun 24, 2004 1:39 pm
by Joe
I have a database table with links to images and I am wondering if there is any way to store all of the table columns in an array and randomize them for putting onto the site. The site would show about 10 random images...

Thanks

Posted: Thu Jun 24, 2004 1:55 pm
by tim
mysql_fetch_array and rand() should work for you.

I may be mistaken (cant find the docs in the mySQL manual) but I think theres a random feature there as well

Posted: Thu Jun 24, 2004 1:59 pm
by tim
this will work better

Code: Select all

<?php
mysql_query ("SELECT * FROM image_table order by RAND() LIMIT 1"); 

?>
this will give you one random image

Posted: Thu Jun 24, 2004 2:10 pm
by Joe
Ahh ok thanks alot tim.

Posted: Thu Jun 24, 2004 2:15 pm
by tim
no problemo