Hi,
I came up with the challenge of making a search form, such that users can select how they want to search:
By Model # (only numbers)
Just one keyword (ex: cellphone = will only return results containing the keyword cellphone)
Multiple keywords (ex: cell phone = will return results containing both the words cell and phone)
Then make these 3 search options as check boxes. I know how to code the sql queries, but I dont know how to code the php so that it selects which proper query based on which checkbox has been selected.
Maybe someone has an example for this, or can describe what method to use. Thanks in advance!
How to make a filtered search with mysql?
Moderator: General Moderators
-
scheinarts
- Forum Commoner
- Posts: 52
- Joined: Wed Jul 25, 2007 2:37 am
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
-
scheinarts
- Forum Commoner
- Posts: 52
- Joined: Wed Jul 25, 2007 2:37 am
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
No no, like concatenating each part to the end of the query.scheinarts wrote:you mean check to see if one of the check boxes has been selected?, but i dont get how to concatenate additional string... you mean conditionals inside the sql string?
Because I was thinking doing this... if(thisCheckBox){run this sql query}
Code: Select all
$query = "SELECT `foo` FROM `table` WHERE";
$query .= $someCondition ? " `title` LIKE '%$title%'" : '';
$query .= ";";