le007 Posted October 16, 2007 Share Posted October 16, 2007 Can anybody pls look and tell me whats wrong with the below? Its just NOT working at all The wrong results keep coming up! if ($prop_type == "%"){ $sql = "SELECT * FROM `cheap_tabl` WHERE (`property_type` like 'Agricultural Land' OR `property_type` like 'Business' OR `property_type` like 'Cafe/Deli' OR `property_type` like 'Commerical Site' OR `property_type` like 'Development Site' OR `property_type` like 'Farm Land' OR `property_type` like 'Franchises' OR `property_type` like 'Garage' OR `property_type` like 'Health and Beauty' OR `property_type` like 'Hotels/B+Bs' OR `property_type` like 'Industrial Unit' OR `property_type` like 'Investment' OR `property_type` like 'Licensed Premises' OR `property_type` like 'New Developments' OR `property_type` like 'Office Share' OR `property_type` like 'Office Unit' OR `property_type` like 'Parking Space' OR `property_type` like 'Public House' OR `property_type` like 'Retail Unit' OR `property_type` like 'Shop' OR `property_type` like 'Supermarket' OR `property_type` like 'Warehouse Unit') and `area` like '$county' and `town_city` like '$town' and `price` > ($minprice + 1) and `price` < ($maxprice + 1) and `bedrooms` > ($minbeds - 1) and `bedrooms` < ($maxbeds + 1) ORDER BY cheap_id DESC LIMIT $from, $max_results"; $sirsql = mysql_query($sql) or die(mysql_error()); } elseif ($prop_type !== "%"){ $sql = "SELECT * FROM `cheap_tabl` WHERE `property_type` like '$prop_type' and `area` like '$county' and `town_city` like '$town' and `price` > ($minprice + 1) and `price` < ($maxprice + 1) and `bedrooms` > ($minbeds - 1) and `bedrooms` < ($maxbeds + 1) ORDER BY cheap_id DESC LIMIT $from, $max_results"; $sirsql = mysql_query($sql) or die(mysql_error()); } if ($prop_type == "%"){ $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM `cheap_tabl` WHERE (`property_type` like 'Agricultural Land' OR `property_type` like 'Business' OR `property_type` like 'Cafe/Deli' OR `property_type` like 'Commerical Site' OR `property_type` like 'Development Site' OR `property_type` like 'Farm Land' OR `property_type` like 'Franchises' OR `property_type` like 'Garage' OR `property_type` like 'Health and Beauty' OR `property_type` like 'Hotels/B+Bs' OR `property_type` like 'Industrial Unit' OR `property_type` like 'Investment' OR `property_type` like 'Licensed Premises' OR `property_type` like 'New Developments' OR `property_type` like 'Office Share' OR `property_type` like 'Office Unit' OR `property_type` like 'Parking Space' OR `property_type` like 'Public House' OR `property_type` like 'Retail Unit' OR `property_type` like 'Shops' OR `property_type` like 'Supermarkets' OR `property_type` like 'Warehouse Unit') and `area` like '$county' and `town_city` like '$town' and `price` > ($minprice + 1) and `price` < ($maxprice + 1) and `bedrooms` > ($minbeds - 1) and `bedrooms` < ($maxbeds + 1)"),0); } elseif ($prop_type !== "%"){ $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM `cheap_tabl` WHERE `property_type` like '$prop_type' and `area` like '$county' and `town_city` like '$town' and `price` > ($minprice + 1) and `price` < ($maxprice + 1) and `bedrooms` > ($minbeds - 1) and `bedrooms` < ($maxbeds + 1)"),0); } Quote Link to comment https://forums.phpfreaks.com/topic/73549-solved-2-queries-not-working/ Share on other sites More sharing options...
teng84 Posted October 16, 2007 Share Posted October 16, 2007 is there an error message? or remove all your condition first to check if it will work then add them one by one thats how you can debug it Quote Link to comment https://forums.phpfreaks.com/topic/73549-solved-2-queries-not-working/#findComment-371108 Share on other sites More sharing options...
le007 Posted October 16, 2007 Author Share Posted October 16, 2007 The error is its showing every property type regardless of the if? Quote Link to comment https://forums.phpfreaks.com/topic/73549-solved-2-queries-not-working/#findComment-371111 Share on other sites More sharing options...
le007 Posted October 16, 2007 Author Share Posted October 16, 2007 The main problem is on my other search page, theres a property type thats just "site" which conflicts with "commercial site" and "development site" Quote Link to comment https://forums.phpfreaks.com/topic/73549-solved-2-queries-not-working/#findComment-371112 Share on other sites More sharing options...
teng84 Posted October 16, 2007 Share Posted October 16, 2007 i dont see any prob with that. can you tell me what is this % in your if and why and if posible better explanation of your goals on that codes Quote Link to comment https://forums.phpfreaks.com/topic/73549-solved-2-queries-not-working/#findComment-371118 Share on other sites More sharing options...
le007 Posted October 16, 2007 Author Share Posted October 16, 2007 the % means if nothing is selected Quote Link to comment https://forums.phpfreaks.com/topic/73549-solved-2-queries-not-working/#findComment-371121 Share on other sites More sharing options...
teng84 Posted October 16, 2007 Share Posted October 16, 2007 since your not using a wild card eg $^[] on your where cause why not use the list operator eg where name in ('teng','astig',etc......) Quote Link to comment https://forums.phpfreaks.com/topic/73549-solved-2-queries-not-working/#findComment-371130 Share on other sites More sharing options...
teng84 Posted October 16, 2007 Share Posted October 16, 2007 WHERE `property_type` in ('Agricultural Land','Business','Cafe/Deli','Commerical Site','Development Site','Farm Land','Franchises', 'Garage','Health and Beauty','Hotels/B+Bs','Industrial Unit','Investment','Licensed Premises','New Developments','Office Share','Office Unit','Parking Space', 'Public House' ,'Retail Unit' ,'Shop','Supermarket','Warehouse Unit') and we use like when we are referring to field which is no exact eg like '%teng' <--match any thing that has teng at the end like '%teng%' <--match any thing that has teng and i guess you need this where `property_type` no in ('teng','astig') <-- returns all record asside from teng and astig Quote Link to comment https://forums.phpfreaks.com/topic/73549-solved-2-queries-not-working/#findComment-371135 Share on other sites More sharing options...
le007 Posted October 17, 2007 Author Share Posted October 17, 2007 teng84 Thank you very very much! You have saved me so much effort - that was really brilliant thinking! IT WORKED!!! YAY!!!!!!!!!!!!!!! :D ;D :D ;D :D Where in no didnt work for some reason but where in did!!! AWESOME!!!!!!!!!!!!!!!!!!!!!!!!! Thank you again!!! Leo Quote Link to comment https://forums.phpfreaks.com/topic/73549-solved-2-queries-not-working/#findComment-371196 Share on other sites More sharing options...
teng84 Posted October 17, 2007 Share Posted October 17, 2007 sorry for thats a typo error just change it to where `property_type` not in Quote Link to comment https://forums.phpfreaks.com/topic/73549-solved-2-queries-not-working/#findComment-371276 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.