DB image randomizer

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

DB image randomizer

Post 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
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post 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
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post 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
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Ahh ok thanks alot tim.
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

no problemo
Post Reply