richo89 Posted April 3, 2009 Share Posted April 3, 2009 I currently have a Dynamic Drop down whereby the user Searches Make then Model. However - how would my query look so that if user just clicked alfa romeo for example and didnt select a model it would show all the alfa romeo's. My current code looks like this: $query=" SELECT * FROM cars WHERE make LIKE '$searchmake' AND model LIKE '$searchmodel'"; if(isset($column_name) and strlen($column_name)>0) { $query = $query . " order by $column_name"; } $query = $query. " limit $eu, $limit "; $result=mysql_query($query); echo mysql_error(); Quote Link to comment https://forums.phpfreaks.com/topic/152435-empty-form-value/ Share on other sites More sharing options...
Maq Posted April 3, 2009 Share Posted April 3, 2009 Something like this: if(isset($searchmodel)) { $query="SELECT * FROM cars WHERE make LIKE '$searchmake' AND model LIKE '$searchmodel'"; } else { $query="SELECT * FROM cars WHERE make LIKE '$searchmake'"; } if(isset($column_name) and strlen($column_name)>0) { $query = $query . " order by $column_name"; } $query = $query. " limit $eu, $limit "; $result=mysql_query($query); echo mysql_error(); Quote Link to comment https://forums.phpfreaks.com/topic/152435-empty-form-value/#findComment-800546 Share on other sites More sharing options...
richo89 Posted April 4, 2009 Author Share Posted April 4, 2009 Thank you i'll give that a try however I have multiple forms so will need to change it slightly. Also... I do have a form for max mileage min mileage etc. Is their a value i could use in the form value so that it searches all records for example? Quote Link to comment https://forums.phpfreaks.com/topic/152435-empty-form-value/#findComment-801067 Share on other sites More sharing options...
richo89 Posted April 5, 2009 Author Share Posted April 5, 2009 anyone? Quote Link to comment https://forums.phpfreaks.com/topic/152435-empty-form-value/#findComment-801720 Share on other sites More sharing options...
Maq Posted April 5, 2009 Share Posted April 5, 2009 I do have a form for max mileage min mileage etc. Is their a value i could use in the form value so that it searches all records for example? Sorry, I don't understand what you want. All records for max/min mileage? Quote Link to comment https://forums.phpfreaks.com/topic/152435-empty-form-value/#findComment-801877 Share on other sites More sharing options...
richo89 Posted April 6, 2009 Author Share Posted April 6, 2009 I have a form that looks like the following: Make Model Min Price Max Price user fills in all the details and it displays the records that meet the query. However, if I leave min price and max price blank without selecting a value it doesnt display anything. Now in my form it looks like this: <form action="cmSearch.php" method="GET"> <select name="searchpricemin"> <option value="" selected="selected">Min Price          </option> <option value="1">£1</option> <option value="100">£100</option> <option value="500">£500</option> <option value="1000">£1000</option> <option value="2000">£2000</option> <option value="3000">£3000</option> <option value="4000">£4000</option> <option value="5000">£5000</option> <option value="6000">£6000</option> <option value="7000">£7000</option> <option value="8000">£8000</option> <option value="9000">£9000</option> <option value="10000">£10000</option> <option value="15000">£15000</option> <option value="20000">£20000</option> <option value="30000">£30000</option> </select> Is there something I can choose here <option value="" selected="selected">Min Price          </option> So that if the user doesnt select a min price it just leaves that blank and continues searching make/model/max price. Quote Link to comment https://forums.phpfreaks.com/topic/152435-empty-form-value/#findComment-802426 Share on other sites More sharing options...
Maq Posted April 6, 2009 Share Posted April 6, 2009 On the next page just do check the same way you check $searchmodel with isset. Quote Link to comment https://forums.phpfreaks.com/topic/152435-empty-form-value/#findComment-802433 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.