Welcome Guest, Not a member yet? Register   Sign In
Constructing search queries
#1

[eluser]RS71[/eluser]
Hey,

I need to construct search queries and I was wondering how I might be able to do this.

My form is basically a couple of inputs and a couple of checkbox arrays. What would be the best approach? Also, I was reading up on queries and what would be faster? "IN ()" or "a = b OR z = Y, etc"

What about the whole GET vs POST?

Thanks in advance for the help
Cheers
#2

[eluser]slowgary[/eluser]
GET vs POST in what context? Some people prefer POST as it makes for cleaner URLs, but users will only be able to bookmark or share the search if it uses GET. As far as security is concerned, there's no different. So it's really up to preference.

As far as the query for your specific app, it's really going to depend on your needs. Using IN() / OR in your query is only going to find instances that contain at least one of the credentials. For instance, if your search were for real estate, you might have checkboxes that represent the following fields:
Code:
_x_ Fireplace
___ Attached Garage
_x_ Central Air
___ Bus Route
If those were your four checkboxes, then the search with "fireplace" and "central air" checked would look like this:
Code:
SELECT * FROM properties
   JOIN property_features ON properties.id = property_features.property_id
   JOIN features ON property_features.feature_id = features.id
   WHERE features.name IN ('fireplace', 'central air')

The problem is that this would return properties that have a fireplace, and properties that have central air, and properties that have both. The use will wonder why some of the results don't have central air, and some of them don't have a fireplace, since that's what they searched for. Switching to OR in your query will not solve the issue, you'd need to concoct an AND query.

The same will be true for your other fields, it will really all depend on your application.

More details may get you more answers. I hope this helps.




Theme © iAndrew 2016 - Forum software by © MyBB