PDA

View Full Version : Multiply randon images



headsortails
13 Jul 2010, 09:19 AM
Hi,

I'm developing an internet forumand part of it will be a 'featured van' section. At the moment we only have 8 (I think) featured vans. This will increase and I cant fit them all across the screen.

I've used PHP load a randon image from a list on each page load and something similar to this would work but for multiple images.

I would need it to select 8 randon pix from a list or directory and display them in a horizontal strip, and a pix is selected it will not try and select it again until the page is relaoded - I wouldn't want 2 pics of the same van in 1 strip.

I can't find any 'of the shelf' goodies to help me do this.

Does anyone have any ideas?

The forum is http://thelatebay.com, and the current banner is quite obvious.

Thanks in advance.

<CrGeary.com/>
13 Jul 2010, 11:30 AM
As you already have a database for your forum ( im assuming so anyway ), then just make another table and put them into that.

Then you can just do a select statement like this:


$r = mysql_query( "SELECT * FROM van_images ORDER BY RAND() LIMIT 8" );
while( $rw = mysql_fetch_assoc( $r ) ){
echo "<img src=\"" . $rw['image_source'] . "\" />";
}

Considering you have a database already, and you say new images might be added, thats probably the way i would do it
---

Otherwise you could put each image into an array: eg,


$vans = array ( 'van.jpg', 'van2.jpg', 'van3.jpg' );

$vans = shuffle( $vans );

for( $i = 0; $i < 9; $i++ ){
echo "<img src=\"" . $vans[$i] . "\" />";
}