Hi,
This script gets info from the database and echos the max amount of results.. ie: id $max is set to 4 it will only get 4 random rows from the db, the idea is to extract say 4 random image links from the db and show them.
The problem im having is the random number can repeat itself. meaning that the same image could show up 4 times or whatever $max is set to.
What i need help with is stopping this script from getting the same info twice. Its easy for me to stop it in the first loop but once it gets to loop 4 the original random number has changed. What i dont want to do is write a moutain of if statements to combat it.
Heres my code.. maybe u can see what im trying to do.
$blockdata = '';
$max = 4;
$image_width = 120;
$image_height = 30;
$res = mysql_query("SELECT COUNT(*) FROM " .user_random_images." WHERE r_active='1'") or die ("".mysql_error());
$num_images = mysql_result($res, 0);
if ($num_images > 0)
{
if ($max > $num_images) { $max = $num_images; } //Stop loop from getting more images than there is in the database
for ($i=1;$i<=$max; $i++) //Loop number of max times
{
$randomid = rand(0,$num_images -1);
$re = mysql_query("SELECT r_filelink,r_url,r_id,r_user_id FROM ".user_random_images." WHERE r_active='1' && r_id='$randomid'") or die ("".mysql_error());
while ($ab = mysql_fetch_array($re,MYSQL_BOTH))
{
extract ($ab);
$blockdata .= '<center>';
$blockdata .= '<a href="'.$ab[1].'">';
$blockdata .= '<img border="0" src="'.$ab[0].'" width="'.$image_width.'" height="'.$image_height.'" alt="" title="Click to open a new window and browse to this website '.$ab[1].' Submitted by: '.$ab[3].'"/>';
$blockdata .= '</a></center><br /><br />';
}
}
}
else
{
$blockdata .= '<center>No Images Found</center>';
}
return $blockdata;
Thanks in advance..