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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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