Jump to content

[SOLVED] PHP more than


UQ13A

Recommended Posts

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

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

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

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

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 :D

Link to comment
https://forums.phpfreaks.com/topic/162600-solved-php-more-than/#findComment-858333
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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