canabatz Posted April 3, 2011 Share Posted April 3, 2011 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 More sharing options...
spiderwell Posted April 3, 2011 Share Posted April 3, 2011 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 https://forums.phpfreaks.com/topic/232555-display-result-if-not-specified/#findComment-1196186 Share on other sites More sharing options...
canabatz Posted April 3, 2011 Author Share Posted April 3, 2011 Thanx ,it did it. Link to comment https://forums.phpfreaks.com/topic/232555-display-result-if-not-specified/#findComment-1196198 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.