omitting one record

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gld4x4
Forum Newbie
Posts: 8
Joined: Wed Feb 18, 2004 6:31 am

omitting one record

Post 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
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post 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");
gld4x4
Forum Newbie
Posts: 8
Joined: Wed Feb 18, 2004 6:31 am

Post 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?
steve@oeic.net
Forum Newbie
Posts: 8
Joined: Wed Feb 18, 2004 2:47 pm

Post by steve@oeic.net »

Code: Select all

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

?>
Post Reply