Jump to content

Recommended Posts

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(); 

Link to comment
https://forums.phpfreaks.com/topic/152435-empty-form-value/
Share on other sites

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(); 

Link to comment
https://forums.phpfreaks.com/topic/152435-empty-form-value/#findComment-800546
Share on other sites

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 &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp  </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 &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp  </option>

 

So that if the user doesnt select a min price it just leaves that blank and continues searching make/model/max price.

Link to comment
https://forums.phpfreaks.com/topic/152435-empty-form-value/#findComment-802426
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.