morpheusoptic
01-15-2005, 06:19 PM
I have successfully finished my registration, login and ad placement page for a free classifieds section of my website that I have been working on. Now that I have a way of my users entering information into the database, I am trying to find a way for them to be able to do an advanced search of everything instead of having to display only a few pre-defined columns from the tables in the database that I have set up, "for now".
The advanced search page is going to be made up of text boxes, radio buttons and check boxes.... I am going to have it set up to have a default setting for everything, so if the user decides not to click a radio button or check a box, or fill out a field, the script will resort to my preset defaults for those categories, to simplify the script.
The biggest feature I need is to allow a user to select a price range of products, say I have 3 set price ranges.... If I set that up in 2 or 3 radio buttons the user can choose from, the value of them will be set to a single variable.... take a look at my current code and I will explain more below it.
$sql = "SELECT * FROM ad_details WHERE ptype LIKE '%$_POST[ptype]%' AND asking < '%$_POST[price]%' AND state LIKE '%$_POST[state]%' ORDER BY price DESC LIMIT 25";
$query = mysql_query($sql);
$total_results = mysql_num_rows($query);
If you look at the asking < $_POST[price], it basically is saying show columns that only have a price less than whatever the variable $_POST['price'] is set to. Now if my form is currently set up to allow the user to search a price at or below $50 or above $50... how do I make the code work. I know with the current way, if they picked below $50, it would only show ads below $50... if they picked above $50, I would have to set the variable really high, and than it would show not only above but also below $50. Hopefully there is a way of doing this easily... I am sure there is because you see it all the time, however I am lost.
Last thing.... I was reading somewhere about database queries and they said the word LIKE in the SQL command means "="... is this true? If not, should I change LIKE to = in the statement above... I need it to equal that variable, that why I placed LIKE in there. Please check they syntax of my statement as I am new to adding all these LIKE & AND words in it, and also parsing variables into the SQL command... I am sure I have errors!
Thanks in advance everyone, I look forward to getting this running.
Paul
The advanced search page is going to be made up of text boxes, radio buttons and check boxes.... I am going to have it set up to have a default setting for everything, so if the user decides not to click a radio button or check a box, or fill out a field, the script will resort to my preset defaults for those categories, to simplify the script.
The biggest feature I need is to allow a user to select a price range of products, say I have 3 set price ranges.... If I set that up in 2 or 3 radio buttons the user can choose from, the value of them will be set to a single variable.... take a look at my current code and I will explain more below it.
$sql = "SELECT * FROM ad_details WHERE ptype LIKE '%$_POST[ptype]%' AND asking < '%$_POST[price]%' AND state LIKE '%$_POST[state]%' ORDER BY price DESC LIMIT 25";
$query = mysql_query($sql);
$total_results = mysql_num_rows($query);
If you look at the asking < $_POST[price], it basically is saying show columns that only have a price less than whatever the variable $_POST['price'] is set to. Now if my form is currently set up to allow the user to search a price at or below $50 or above $50... how do I make the code work. I know with the current way, if they picked below $50, it would only show ads below $50... if they picked above $50, I would have to set the variable really high, and than it would show not only above but also below $50. Hopefully there is a way of doing this easily... I am sure there is because you see it all the time, however I am lost.
Last thing.... I was reading somewhere about database queries and they said the word LIKE in the SQL command means "="... is this true? If not, should I change LIKE to = in the statement above... I need it to equal that variable, that why I placed LIKE in there. Please check they syntax of my statement as I am new to adding all these LIKE & AND words in it, and also parsing variables into the SQL command... I am sure I have errors!
Thanks in advance everyone, I look forward to getting this running.
Paul