且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

多个内部联接擦除属性

更新时间:2023-12-02 09:24:16

您的问题是每个列都具有相同的名称.当您的结果转换为PHP数组时,后面的列将使用相同的索引/列名覆盖第一列.您必须为每个列赋予唯一的标识符,才能访问每个单个值.

Your problem is that each column has the same name. When your result is converted to an PHP array the later columns overwrite the first column with the same index / column name. You have to give each column a unique identifier, to access each single value.

SELECT *, p.firstname as p_firstname, p.lastname AS p_lastname,
p1.first_name AS p1_firstname, [...]
FROM albums  a
INNER JOIN people p ON a.idauthor = p.id
INNER JOIN people p1 ON a.idcompositor = p1.id
INNER JOIN people p2 ON a.idfeat = p2.id
where a.idalbum=:id

作为替代方案,您可以使用另一种访存样式,该样式将按其列号插入列到数组中.(如果您使用的是PDO,请参见 http://www.php.net/manual/en/pdostatement.fetch.php )

As an alternative you can use another fetch style, which inserts the columns by its column number into the array. (If you are using PDO, see http://www.php.net/manual/en/pdostatement.fetch.php)