Is there a more succinct way to write the below code?
$myQuery = "
SELECT * FROM `rooms`
WHERE (
`Facility1` IN ($inList)
OR `Facility2` IN ($inList)
OR `Facility3` IN ($inList)
OR `Facility4` IN ($inList)
OR `Facility5` IN ($inList)
OR `Facility6` IN ($inList)
OR `Facility7` IN ($inList)
OR `Facility8` IN ($inList)
OR `Facility9` IN ($inList)
) AND `Location` LIKE '".$Location."%'
AND `RoomType` LIKE '".$RoomType."%'
ORDER BY CONVERT(`Capacity`, SIGNED)
";
In order to make this more compact, you could write code to build the query for you:
But really, the issue with a query like the one you show is not about the code, but about the structure of your data model, which is not “normalized”.
“Database normalization is the process of organizing the fields and tables of a relational database to minimize redundancy and dependency.”. You have 9 “Facility” fields, and this gives you three problems (not mentioning the difficulty of building queries):
The issue here is that the “Facility” should be an “entity” in itself, and as such, should be contained in its own table; other tables would just “refer” to the canonical Facility table. This avoids the problems I mention through a number of well-known relational database techniques.
I sugges you read up on database normalization and consider reworking your database’s structure to conform to having a Facility table, and (as I deduce you will need from looking at the query) an “intermediate” facility_room table which would map facilities to rooms.
Here’s a place to get started: http://en.wikipedia.org/wiki/Database_normalization
and here: http://www.devshed.com/c/a/MySQL/An-Introduction-to-Database-Normalization/