Mirkules Posted October 12, 2007 Share Posted October 12, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/72955-tablename-not-present-in-result-assoc-array/ Share on other sites More sharing options...
Barand Posted October 12, 2007 Share Posted October 12, 2007 In 20+ years using SQL in various flavours I haven't come across result sets with table.column, only column names or column aliases (or indexed results as in mysql_fetch_row) Quote Link to comment https://forums.phpfreaks.com/topic/72955-tablename-not-present-in-result-assoc-array/#findComment-368008 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.