Random image
Posted: Thu Feb 19, 2004 10:35 am
I have a script that selects random images, the problem is it keeps picking the first record in the database and the other 2 are random. Can anybody please help. Below is the code used.
<?
$db = MYSQL_CONNECT("localhost",rrrrr,rrrrrr) OR DIE ("Unable to connect to database");
@mysql_select_db(attorney_images,$db) or die ("Unable to select database");
$result = mysql_query ("SELECT *FROM all_images order by RAND ()LIMIT 3");
if($myrow = mysql_fetch_array($result))
{
do{
echo"<td><table width='100%'><tr><td align='center'><table border='1'><tr><td><img src=http://rrrrrr.com/images/pics/$myrow[0]
</td></tr></table></td></tr><tr><td align='center'><b><font color='000000' size='-2'>$myrow[2]<br>$myrow[4]</font><br>$myrow[3]</b></font></td></tr></table>";
}while ($myrow = mysql_fetch_array($result));
}else{
echo "bad image";
}
?>
<?
$db = MYSQL_CONNECT("localhost",rrrrr,rrrrrr) OR DIE ("Unable to connect to database");
@mysql_select_db(attorney_images,$db) or die ("Unable to select database");
$result = mysql_query ("SELECT *FROM all_images order by RAND ()LIMIT 3");
if($myrow = mysql_fetch_array($result))
{
do{
echo"<td><table width='100%'><tr><td align='center'><table border='1'><tr><td><img src=http://rrrrrr.com/images/pics/$myrow[0]
</td></tr></table></td></tr><tr><td align='center'><b><font color='000000' size='-2'>$myrow[2]<br>$myrow[4]</font><br>$myrow[3]</b></font></td></tr></table>";
}while ($myrow = mysql_fetch_array($result));
}else{
echo "bad image";
}
?>