UQ13A Posted June 17, 2009 Share Posted June 17, 2009 When i run this script it shows all the results even when days_left is less than 2 can you tell me what i have done wrong this is only part of the script $query = ("SELECT * FROM `sell` WHERE `houses`='$make' AND `days_left`>'2' OR `model`='$model' "); $result = mysql_query($query); $numResults = mysql_num_rows($result); if ($numResults == 0) { echo "<u><center>Your search results for $make $model returned 0 results</center></u><br /><br /><br /><br />"; exit; } Link to comment https://forums.phpfreaks.com/topic/162600-solved-php-more-than/ Share on other sites More sharing options...
akitchin Posted June 17, 2009 Share Posted June 17, 2009 you're checking the value of what i assume is an integer in the database (at least i hope it is) against the STRING '2'. remove the single quotes to have SQL treat it as an integer for comparison: SELECT * FROM `sell` WHERE `houses`='$make' AND `days_left`>2 OR `model`='$model' you only need to encapsulate strings in single quotes when you use them in a query - strict numbers should be used without. Link to comment https://forums.phpfreaks.com/topic/162600-solved-php-more-than/#findComment-858161 Share on other sites More sharing options...
UQ13A Posted June 17, 2009 Author Share Posted June 17, 2009 thanks for that but when i use the code you said i still got the same, when i remove OR `model`='$model' from SELECT * FROM `sell` WHERE `houses`='$make' AND `days_left`>2 then the script works and i dont need it like this thought Link to comment https://forums.phpfreaks.com/topic/162600-solved-php-more-than/#findComment-858169 Share on other sites More sharing options...
akitchin Posted June 17, 2009 Share Posted June 17, 2009 what are you trying to specify with your where conditions? as in, how should that OR be grouped? Link to comment https://forums.phpfreaks.com/topic/162600-solved-php-more-than/#findComment-858261 Share on other sites More sharing options...
UQ13A Posted June 17, 2009 Author Share Posted June 17, 2009 what are you trying to specify with your where conditions? as in, how should that OR be grouped? Well i dont think i explained it properly, basically my script shows houses that are for sale but that are under the days_left limit example; A house which has anything under 1 day remaining will not show but everything else will Link to comment https://forums.phpfreaks.com/topic/162600-solved-php-more-than/#findComment-858277 Share on other sites More sharing options...
akitchin Posted June 17, 2009 Share Posted June 17, 2009 then it sounds like what you'll want to do is separate the two sets of clauses: WHERE (`houses` = '$make' OR `model` = '$model') AND `days_left` > 2 this forces it to choose houses that will EITHER match $make or $model, AND has days_left greater than two. Link to comment https://forums.phpfreaks.com/topic/162600-solved-php-more-than/#findComment-858313 Share on other sites More sharing options...
UQ13A Posted June 17, 2009 Author Share Posted June 17, 2009 then it sounds like what you'll want to do is separate the two sets of clauses: WHERE (`houses` = '$make' OR `model` = '$model') AND `days_left` > 2 this forces it to choose houses that will EITHER match $make or $model, AND has days_left greater than two. Thanks it works perfectly needed to edit it a bit but yes it work Link to comment https://forums.phpfreaks.com/topic/162600-solved-php-more-than/#findComment-858333 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.