bothwell Posted June 29, 2008 Share Posted June 29, 2008 ... 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? Link to comment https://forums.phpfreaks.com/topic/112461-solved-php-numeric-comparison-not-returning-results/ Share on other sites More sharing options...
DarkWater Posted June 29, 2008 Share Posted June 29, 2008 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. Link to comment https://forums.phpfreaks.com/topic/112461-solved-php-numeric-comparison-not-returning-results/#findComment-577415 Share on other sites More sharing options...
bothwell Posted June 29, 2008 Author Share Posted June 29, 2008 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. Link to comment https://forums.phpfreaks.com/topic/112461-solved-php-numeric-comparison-not-returning-results/#findComment-577423 Share on other sites More sharing options...
DarkWater Posted June 29, 2008 Share Posted June 29, 2008 You always should use it on associatively indexed arrays. Also, echo $intRent to make sure it contains what you expect. Link to comment https://forums.phpfreaks.com/topic/112461-solved-php-numeric-comparison-not-returning-results/#findComment-577428 Share on other sites More sharing options...
bothwell Posted June 29, 2008 Author Share Posted June 29, 2008 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!) Link to comment https://forums.phpfreaks.com/topic/112461-solved-php-numeric-comparison-not-returning-results/#findComment-577441 Share on other sites More sharing options...
DarkWater Posted June 29, 2008 Share Posted June 29, 2008 I don't think an index is necessary for that. Link to comment https://forums.phpfreaks.com/topic/112461-solved-php-numeric-comparison-not-returning-results/#findComment-577443 Share on other sites More sharing options...
PFMaBiSmAd Posted June 29, 2008 Share Posted June 29, 2008 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. Link to comment https://forums.phpfreaks.com/topic/112461-solved-php-numeric-comparison-not-returning-results/#findComment-577481 Share on other sites More sharing options...
bothwell Posted June 29, 2008 Author Share Posted June 29, 2008 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. Link to comment https://forums.phpfreaks.com/topic/112461-solved-php-numeric-comparison-not-returning-results/#findComment-577513 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.