Page 1 of 1

Help with MySQL Select statement in PHP code

Posted: Sun Feb 03, 2008 3:22 pm
by satcom
I've got the following SQL statement that I'm wanting to customize for a website I'm working on.

$query="SELECT * FROM #__alberghi_facilities WHERE id IN (".$item->facilities.")";

Basically, I'm wanting to not include certain id's in the query.

For example, lets say that $item->facilities included 3, 5, 8, 9 and I wanted to exclude 8 from the query.

I want the select to pull the records except 5 and 9. I know that an and statement is needed but I'm not sure how to do it.

Any help would be appreciated.

Re: Help with MySQL Select statement in PHP code

Posted: Sun Feb 03, 2008 4:44 pm
by Christopher
Are you asking how to use the IN() operator or how to remove numbers from $item->facilities? If the latter, is $item->facilities as string or array?

Re: Help with MySQL Select statement in PHP code

Posted: Sun Feb 03, 2008 5:06 pm
by satcom
It is an array. I'm wanting to exclude certain results from the query.

This is what I was thinking I just don't know how to write it.


$query="SELECT * FROM #__alberghi_facilities WHERE id IN (".$item->facilities.") and id isnot '8' ";

I know that is written incorrectly. Also there are times when several id's need to be excluded. Actually it is always going to be the same id's that are excluded.

Re: Help with MySQL Select statement in PHP code

Posted: Sun Feb 03, 2008 6:07 pm
by Christopher
Have you looked at the PHP documentation for arrays:

http://www.php.net/manual/en/ref.array.php

There are functions to do all sorts of things to arrays (no pun intended ;)).