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

Link to comment
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.