a1amattyj Posted September 22, 2010 Share Posted September 22, 2010 Hello, For some reason the following query returns 0 rows: $query = mysql_query(" SELECT * FROM `businesses_touchlocal_temp` WHERE `postcode` = '".$this_business['postcode']."' LIMIT 1 ")or die(mysql_error()); echo mysql_num_rows($query); echo "<br />"; var_dump($this_business['postcode']); 0 string( "SE8 5" But this returns 1 row: $query = mysql_query(" SELECT * FROM `businesses_touchlocal_temp` WHERE `postcode` = 'SE8 5' LIMIT 1 ")or die(mysql_error()); echo mysql_num_rows($query); 1 Kind of banging my head here. Thanks! Quote Link to comment Share on other sites More sharing options...
Miss_Rebelx Posted September 22, 2010 Share Posted September 22, 2010 I'm curious why your var dump says your string has 8 characters... that may be something. Your logic aside from that seems fine. Quote Link to comment Share on other sites More sharing options...
a1amattyj Posted September 22, 2010 Author Share Posted September 22, 2010 I'm curious why your var dump says your string has 8 characters... that may be something. Your logic aside from that seems fine. Ignore the 8, that was me altering the code, I can't understand why it's not doing it for the first query Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 22, 2010 Share Posted September 22, 2010 You should start by separating the query string from the query execution and echoing it to the screen so you can make sure it actually is what you'd expect. Quote Link to comment Share on other sites More sharing options...
a1amattyj Posted September 22, 2010 Author Share Posted September 22, 2010 You should start by separating the query string from the query execution and echoing it to the screen so you can make sure it actually is what you'd expect. Tried that, it is what I thought it would be. Quote Link to comment Share on other sites More sharing options...
Miss_Rebelx Posted September 22, 2010 Share Posted September 22, 2010 I'm curious why your var dump says your string has 8 characters... that may be something. Your logic aside from that seems fine. Ignore the 8, that was me altering the code, I can't understand why it's not doing it for the first query So what was the actual dump? Kinda pointless to show us an 'edited' or 'doctored' version of var_dump(). Quote Link to comment Share on other sites More sharing options...
a1amattyj Posted September 22, 2010 Author Share Posted September 22, 2010 I'm curious why your var dump says your string has 8 characters... that may be something. Your logic aside from that seems fine. Ignore the 8, that was me altering the code, I can't understand why it's not doing it for the first query So what was the actual dump? Kinda pointless to show us an 'edited' or 'doctored' version of var_dump(). Sorry, was not intentional in the least string(5) "SE8 5" Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted September 22, 2010 Share Posted September 22, 2010 Have you tried adding mysql_real_escape_string() around your variable...dont know why that would cause an issue with the value you gave but it might be the problem and you should always use it anyway. Quote Link to comment Share on other sites More sharing options...
a1amattyj Posted September 22, 2010 Author Share Posted September 22, 2010 It's heavily disliking that variable.. I managed to get a fix for it but updating the postcode from an off-site location.. Kind of killing the idea of a var, but stuck $this_business['postcode'] = "SE8 5DA"; at the top of the page. Thanks for the posts Quote Link to comment Share on other sites More sharing options...
Miss_Rebelx Posted September 22, 2010 Share Posted September 22, 2010 I'm also curious about the quoting... try saving the array'd value into it's own variable, then putting that variable in the SQL statement. $postcodeVariable = $this_business['postcode'];$sql = "SELECT * FROM `businesses_touchlocal_temp` WHERE `postcode` = '" . $postcodeVariable ."'LIMIT 1;";$query = mysql_query($sql);echo mysql_num_rows($query); 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.