Jump to content

MYSQL PHP SELECT


a1amattyj

Recommended Posts

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(8) "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!

Link to comment
https://forums.phpfreaks.com/topic/214113-mysql-php-select/
Share on other sites

 

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().

Link to comment
https://forums.phpfreaks.com/topic/214113-mysql-php-select/#findComment-1114170
Share on other sites

 

 

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"

Link to comment
https://forums.phpfreaks.com/topic/214113-mysql-php-select/#findComment-1114171
Share on other sites

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);

 

Link to comment
https://forums.phpfreaks.com/topic/214113-mysql-php-select/#findComment-1114185
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.