Jump to content

[SOLVED] PHP numeric comparison not returning results


bothwell

Recommended Posts

... even though technically it should, oh yes. Quick snippet of what I'm trying to do:

 

$test = "SELECT * FROM property_info WHERE rent<=$intRent";
$res = mysql_query($test);
$data = mysql_fetch_assoc($res);

print "data:". $data[rent] .";";

 

This just returns a blank result in the print - if I take out the WHERE clause then I do get a result, so it seems to me that it's the comparator itself that I've borked. This worked in PHP4, but not PHP5, so there's a difference between the two - what am I missing?

I see something wrong already, but it's not causing your error.

 

Show me where you set $intRent, because that's probably the issue.

 

So now, the other thing I see incorrect is the fact that you don't use ' ' around your array key names.  You ALWAYS should.

I see something wrong already, but it's not causing your error.

 

Show me where you set $intRent, because that's probably the issue.

 

So now, the other thing I see incorrect is the fact that you don't use ' ' around your array key names.  You ALWAYS should.

 

$intRent comes in through a form:

 

if(!isset($_POST['strTypes']) || !isset($_POST[intBeds]) || !isset($_POST[intRent])) 
die ("No search data!");
  
$strTypes = $_POST['strTypes']; $intBeds = $_POST[intBeds]; $intRent = $_POST[intRent];  

 

I actually took out the ''s because I assumed they were only for strings, heh! I had them all enclosed that way in the PHP4 version but removed them for the integers only in the PHP5 one in the belief that I was doing the right thing.

 

Also, echo $intRent to make sure it contains what you expect.

 

Haha, no it doesn't! It's using the record index number instead of the actual value. Why would PHP4 let me get away with that? How strange.

 

Another quick, related question - is it even worthwhile having an index on this table? I mean it's only got "rent" and "rent_id" in it. I wrote this ages ago and I'd never made a database schema before, but having an index here strikes me as gloriously inefficient and pointless. Would this be a fair accusation?

 

(and thanks for the help!)

It's using the record index number instead of the actual value. Why would PHP4 let me get away with that?
It is probably something in the code that is building the form. Code only does what the logic in it tells it to do. You would need to post the code that builds the form to get specific help with what it is or is not doing.

It's using the record index number instead of the actual value. Why would PHP4 let me get away with that?
It is probably something in the code that is building the form. Code only does what the logic in it tells it to do. You would need to post the code that builds the form to get specific help with what it is or is not doing.

 

Oh, no, it's cool - I should have done what DarkWater told me to do and echoed the input to make sure it was what I wanted, then I would have seen that it was trying to compare a value with an index number. I was just surprised that PHP4 was masking that and doing what I wanted it to do, rather than what I was telling it to do. :)

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.