Jump to content

display result if not specified


canabatz

Recommended Posts

Hi i got a search form and when im searhing for result i get nothing.

 

i got 5 search fields :

 

1. Erea

2. category

3. subcategory

4. from price

5. to price

 

if im not specifieing  from price and to price i get blank result ,if i do specify the from price to price ,then i get the results.

 

this is the code im using to get the results.

$sql=mysql_query("select * from posts where erea = '$erea' and category = '$category' and sub_category = '$subcategory' and price >= '$fromprice' and price <= '$toprice'");

 

what i want is to get the result even if i didnt specify the price from, to .

 

thanx

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/232555-display-result-if-not-specified/
Share on other sites

perhaps an if statement to generate 2 SQL statements, one with prices to and from, and one without?

 

if (!$fromprice && !$toprice) //this assumes you set these variables to false previously, and only fill them if there are values from the form, change accordingly to suit your code

{

$sql=mysql_query("select * from posts where erea = '$erea' and category = '$category' and sub_category = '$subcategory' );

}

else

{

$sql=mysql_query("select * from posts where erea = '$erea' and category = '$category' and sub_category = '$subcategory' and price >= '$fromprice' and price <= '$toprice'");

}

 

I am sure someone will come up with something better...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.