Randomly Generating PHP Image Array?

Associate
Joined
12 Aug 2004
Posts
1,009
Location
Glasgow, Scotland
Hi folks :)

I have a horizontal bar on my website that produces 7 different images from a database and instead of only letting the visitors see the first 7 images I would like them to see all them, so I've been trying to see if I make the array randomly generate the images every time the page is loaded.

The current code is as follows:

Code:
echo "<table border='0' cellpadding='0' cellspacing='4'>\r\n";
	
	$top_row = "";
	$bottom_row = "";
	$counter = "";
	
	while($counter <= 6 && $villa = mysql_fetch_array($villas))
	{
		$counter++;
		
		$villaid = $villa['villaid'];
		$thumbnail = $villa['thumbnail'];
		$categoryid = $villa['categoryid'];
		$name = $villa['name'];
		$thumbnail = htmlspecialchars($villa['thumbnail']);
		$categoryid = htmlspecialchars($villa['categoryid']);
		$name = htmlspecialchars($villa['name']);
				
		$top_row .= "<td class='villas-top'>";
		$top_row .= "<a href='index.php?page=villapage&villaid=$villaid'>";
		$top_row .= "<img alt='$name Thumbnail' width='75px' height='70px' src='$thumbnail' /></a></td>\r\n";
		
		$bottom_row .= "<td class='villas-bottom'><a style='color: #ffffff; background-color: #0e5e9c; text-decoration: none;' title='$categoryid Bedrooms' href='index.php?page=villapage&villaid=$villaid'>$categoryid Bedrooms</a></td>\r\n";
	}
	
	echo "<tr>\r\n$top_row</tr>\r\n";
	echo "<tr>\r\n$bottom_row</tr>\r\n";
	echo "</table>";

Is there a relatively simple way of doing this?

Thanks
 
Associate
OP
Joined
12 Aug 2004
Posts
1,009
Location
Glasgow, Scotland
Cheers Paul,

I really should get a PHP / mySQL book(s) :)

I've got a book already called "Build your own database driven website using PHP & MySQL" but it's served it's purpose really and I could do with something with a bit more information in it, look's like I'll be hitting Amazon's shelfs again pretty soon :p

Thanks for the help,

Steven.
 
Back
Top Bottom