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.
Help with MySQL Select statement in PHP code
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Help with MySQL Select statement in PHP code
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?
(#10850)
Re: Help with MySQL Select statement in PHP code
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.
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.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Help with MySQL Select statement in PHP code
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
).
http://www.php.net/manual/en/ref.array.php
There are functions to do all sorts of things to arrays (no pun intended
(#10850)