|
-
Feb 9th, 2009, 11:33 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] How to search db from URL Variables, Can't get this!
Hello...
I am trying to create a sql search on a master catalog page. I want to narrow down items based on selected information in a few dropdown boxes.
I have three: Make, Model, Color ... upon clicking 'submit' the results page is shown with the search results.
They are all dynamic menus. Their values correspond to their primary IDs from their mysql table.
I also added a label called "All" with no value, so the user can leave any of the menuboxes as "All" when searching.
I then pass the information to the search results page using the get method on the form (using URL Variables).
What throws me off is the "All" that I would like to have in the boxes.
My search results page is made to get the numeric information from the URL variables passed from the dropdown search boxes.
My search works great if all fields are entered as of right now.
However, as I mentioned, I have the value set to nothing for the "All" option in the dropdown box, so the URL variable is blank.
How can I modify the sql to incorporate that is there is no value for the url variable, then do not use it in the where clause of the sql?
Code:
$make_rs = "-1";
if (isset($_GET['make'])) {
$man_rs = $_GET['make'];
}
$model_rs = "-1";
if (isset($_GET['model'])) {
$level_rs = $_GET['model'];
}
$color_rs = "-1";
if (isset($_GET['color'])) {
$model_rs = $_GET['color'];
}
mysql_select_db($database_connectDB, $connectDB);
$query_rs = sprintf("SELECT * FROM prod_items WHERE make_id = %s AND model_id=%s AND color_id = %s", GetSQLValueString($make_rs, "int"),GetSQLValueString($model_rs, "int"),GetSQLValueString($color_rs, "int"));
... that is my search now.
I am using php/mySQL. :-)
This is kind of like the search feature at www.cars.com. One can select "All" for makes, "all" for model, and so on.
Thank you!!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|