Mr Chris Posted March 10, 2008 Share Posted March 10, 2008 Hi All, I have a very simple piece of condition checking that I’m having trouble with: I only want to use this condition IF $from_price OR $to_price is empty then don't add the below query: if(!empty($from_price) || ($to_price)) { $add .= " AND price BETWEEN '$from_price' AND '$to_price'"; } However, if $from_price has a value and $to_price does not it still outputs this condition (and vice versa). Can anyone help? Thanks Quote Link to comment Share on other sites More sharing options...
Baabu Posted March 10, 2008 Share Posted March 10, 2008 if(isset($from_price) && isset($to_price)) { $add .= " AND price BETWEEN '$from_price' AND '$to_price'"; } try this ...if both are set then this query will be added..else not Quote Link to comment Share on other sites More sharing options...
Mr Chris Posted March 10, 2008 Author Share Posted March 10, 2008 Thanks, Just one more i'm stuck with on a condition check. If $bathroom is not empty and less than 4 otherwise use the other condition if(!empty($bathrooms) && $bathrooms < '4') { $add .= " AND bathrooms = '$bathrooms'"; } if(!empty($bathrooms) && $bathrooms > '5') { $add .= " AND bathrooms > '5'"; } Quote Link to comment Share on other sites More sharing options...
Mr Chris Posted March 10, 2008 Author Share Posted March 10, 2008 Doh, that does work! Please ignore me, thanks anyway!! Quote Link to comment Share on other sites More sharing options...
revraz Posted March 10, 2008 Share Posted March 10, 2008 You should probably wrap this though $bathrooms > '5' to ($bathrooms > 5) Quote Link to comment 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.