Jump to content

Recommended Posts

Hello Everybody,

 

I'm having a problem with the result set when I fetch the associative array.  First, let's start with the SQL statement:

 

$query = "SELECT a.id FROM test a";

 

The table "test" is aliased as "a".  Now I need to reference that field by using the tablename:

 

$result = mysql_query($query, $db);
while ($row = mysql_fetch_assoc($result))
{
var_dump($row);
echo "\n";
echo "id: " . $row['a.id'] . "\n";
}

 

Here is the output:

 

array(1) {
  ["id"]=>
  string(1) "1"
}

id

 

As you can see, the echo statement did nothing, but the row DOES contain values referenced by just "id".  Furthermore, if I simply put: 

echo $row['id'];

the value is present.  I am almost 100% sure that I have been able to do this in the past (on different servers).

 

Finally, if I use

mysql_result($row, 0, "a.id")

I am able to see the value.

 

I am using MySQL 5.0.45 and PHP 5.2.4 in OS X.  I have also tried connecting from my OS X machine to a 4.2.11 MySQL server and running the same script with no luck.

 

It's worth noting that a similar bug exists in MySQL, but ONLY when transitioning from version 4.x to 5.x.  However, I have not upgraded (this is a clean install), and moreover, it doesn't work in 4.2.11 either. (http://bugs.mysql.com/bug.php?id=14897)

 

Any help would be appreciated (as always, my bet is that I have been staring at this for too long and that it's something really simple). I'm now starting to wonder whether the row associative array ever even contained table names (though I could have sworn that I did it in the past)....

 

Mirkules

 

P.S. I'm new to the forums, so please be gentle :)

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.