Forum Moderators: coopster

Message Too Old, No Replies

excluding one result from a sql query

         

bysonary

4:19 pm on Feb 14, 2007 (gmt 0)

10+ Year Member



hello,

I was curious, mainly because I am going to need to implement this.

Is there anyway I can exclude just one result from the database based upon the value of a field, for example i want to exclude the field with an ID of 1 but get all the other fields in the database.

is this possible and can anyone tell me how?

PS: I had thought about doing something like


$query1 = mysql_query("SELECT * FROM table ORDER BY id ASC");

while ($row = mysql_fetch_array($query1,MYSQL_ASSOC))
{
$id = $row['id'];
if ($id == 1)
{
//DO NOT DISPLAY ITEM
}
else
{
//DISPLAY ALL OTHER ITEMS
}
}

it is the DO NOT DISPLAY ITEM and DISPLAY ALL OTHER ITEMS I cant get my head around so if someone could help me out I would appreciate it.

Thanks

mcibor

4:32 pm on Feb 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can ask:

$query1 = mysql_query("SELECT * FROM table WHERE id <> '1' ORDER BY id ASC");

or use the NOT IN structure:

$query1 = mysql_query("SELECT * FROM table WHERE id NOT IN ('1', '3') ORDER BY id ASC");

Regards
Michal

bysonary

9:42 pm on Feb 14, 2007 (gmt 0)

10+ Year Member



Cheers mate that works a charm :-) i opted for

SELECT * FROM table WHERE <> '1' ORDER BY id ASC

Thanks again