#20078 [Bgs]: Error with left join with mysql_fetch_array()

From: Date: Fri, 25 Oct 2002 14:08:44 +0000
Subject: #20078 [Bgs]: Error with left join with mysql_fetch_array()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-23305@lists.php.net to get a copy of this message
ID: 20078 Updated by: hholzgra@php.net Reported By: f.giovannini@netechnologies.it Status: Bogus Bug Type: MySQL related Operating System: Linux 2.4.18 PHP Version: 4.2.1 New Comment: Please understand how left joins work, it is expected behavior that they return NULL values for the right side tables field if no matching entry for the join condition is found so B.P is NULL on the second row, it is just that you have not defined *which* P you want and sometimes you get A.P which is 1, while under other circumstances you get B.P which is NULL try select A.P as A_P, B.P as B_P from A left join B on (A.index_c=B.index_c) try to avoid ambiguos field names in result sets using 'AS', and you will get predictable results. 'nough said! Previous Comments: ------------------------------------------------------------------------ [2002-10-25 06:05:27] georg@php.net As I told you before, it's not a bug in PHP, it's the expected result. Please visit http://www.php.net/support.php or http://www.mysql.com/documentation/lists.html Georg ------------------------------------------------------------------------ [2002-10-25 05:44:01] f.giovannini@netechnologies.it Why in the php 4.1.2 is ok? The problem is the value NULL.... it not exist in database... why php retrive an inexistent value ------------------------------------------------------------------------ [2002-10-25 04:49:07] hholzgra@php.net that's one of the reasons why you should never use 'select * from ...' -> you haven't specified *which* P column you want, A.P or B.P php gives you B.P as P while the cmd line cliebt chose to display A.P ... ------------------------------------------------------------------------ [2002-10-25 04:32:17] georg@php.net Sorry, but your problem does not imply a bug in PHP itself. For a list of more appropriate places to ask for help using PHP, please visit http://www.php.net/support.php as this bug system is not the appropriate forum for asking support questions. Thank you for your interest in PHP. If you use mysql_fetch_array with MYSQL_FETCH_ASSOC, be sure that fieldnames are unique. Georg ------------------------------------------------------------------------ [2002-10-25 04:23:20] msopacua@php.net What 'not enough information' meens in this case, is the lack of a short, self contained, copy/paste/run script, so we can try to reproduce the problem. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/20078 -- Edit this bug report at http://bugs.php.net/?id=20078&edit=1

« previous php.bugs (#23305) next »