PDA

View Full Version : PHP SQL help



opel
October 25th, 2006, 07:29 AM
I am trying to create a sql statement that will select all records EXCEPT for certain content ID that I will manually specify. I'm a newbie to PHP so not sure what the correct SQL statement would be : lmow it would be something like

"SELECT contentId, contentName,contentText, contentDisplay FROM content WHERE contentDisplay='Yes"...Need this bit to be where contentID is not equal to 1, 2, 3 etc "

Any help would be appreciated.

Cheers

evildrummer
October 25th, 2006, 07:36 AM
you could try
`SELECT * FROM content WHERE contentDisplay != '2'` where 2 is the row is the one you DONT want to display

evildrummer
October 25th, 2006, 07:37 AM
you could try
`SELECT * FROM content WHERE contentDisplay != '2'` where 2 is the row is the one you DONT want to display

skOOb
October 25th, 2006, 08:06 AM
SELECT contentId, contentName,contentText, contentDisplay FROM content WHERE contentDisplay='Yes' AND contentID NOT IN (1, 2, 3, 4, 5)
You could just seperate the ID's that you don't want with commas and use the NOT IN listing.

opel
October 25th, 2006, 08:07 AM
if I want to add more thant one row would it be =

!= '2','3'.'4'

or

!= '2,3,4'

Cheers for fast reply

opel
October 25th, 2006, 08:22 AM
if I want to add more thant one row would it be =

!= '2','3'.'4'

or

!= '2,3,4'

Cheers for fast reply

sorry skoob never saw your reply. Seem to be having problems wit the board it is missing out topics and making me log in every time I want to see a page.

skOOb
October 25th, 2006, 08:52 AM
did that work for you then?

opel
October 25th, 2006, 08:56 AM
I'm at work at the moment I'll try it over next couple of days when I get a chance and let you know. Thanks.

bwh2
October 25th, 2006, 09:45 AM
sk00b's NOT IN method is the answer.

evildrummer
October 25th, 2006, 01:51 PM
I was guessing with the !=

bwh2
October 25th, 2006, 02:07 PM
!= will work if you only want to exclude one value (at a time).