Page 1 of 1

omitting one record

Posted: Wed Feb 18, 2004 6:31 am
by gld4x4
Can anybody please help.

I have images listed in a database, I select random images but would like not to select one certain image, is there anyway to do that? My code is listed below.
********************
<?

$db = MYSQL_CONNECT("localhost",xxxxx,xxxxx) 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://xxxxxx/images/attorneys/$myrow[0]
</td></tr></table></td></tr><tr><td align='center' valign='middle'><b><font size='-2'><b>$myrow[2]<br><a href='http://$myrow[4]'><font size='-2'>$myrow[4]</font></a><br>$myrow[3]</b></font></td></tr></table>";
}while ($myrow = mysql_fetch_array($result));
}else{
echo "bad image";
}
?>
********************************

Thanks

Posted: Wed Feb 18, 2004 6:32 am
by d3ad1ysp0rk
$result = mysql_query("SELECT * FROM all_images order by RAND()LIMIT 3");
to

Code: Select all

$result = mysql_query("SELECT * FROM all_images WHERE `img` != 5 order by RAND()LIMIT 3");

Posted: Wed Feb 18, 2004 7:53 am
by gld4x4
Thanks for the reply but that did not work. all_images table is set up as follows:

image (varchar)
name (varchar)
site (varchar)
id (auto_increment)

the image i do not want to display has an id=1
Does this help?

Posted: Wed Feb 18, 2004 3:11 pm
by steve@oeic.net

Code: Select all

$result = mysql_query("SELECT * FROM all_images WHERE id != 1 order by RAND()LIMIT 3"); 

?>