从两个表的JOIN查询中检索数组时出现错误


error on array retrieved from JOIN query on two tables

希望我的标题清楚。我试图从两个表检索结果。所以我需要从名为"albums"的表中获取所有内容(因此需要*)。并且我只想要所有匹配(与album_id)表'贡献者'的结果。

$result = mysql_query("SELECT * FROM albums LEFT JOIN contributors ON albums.album_id = 
contributors.album_id ORDER BY albums.datum DESC; ") or die(mysql_error());
$aantal_rijen = mysql_num_rows($result);
if ($aantal_rijen > 0) {
for ($i = 0; $i < $aantal_rijen; $i++){

$contributors[] = mysql_result($result, $i, 'contributors');}

,但我得到一个类似的错误列表:

MySQL result index .

连接两个表对我来说是全新的,也许这不是我要去的方式,但也许这只是一个简单的错误在这段代码中,无论如何,我被困在这里,

欢迎所有帮助thx S

http://php.net/manual/en/function.mysql-result.php

<

字段/strong>

被检索字段的名称或偏移量。

可以是字段的偏移量、字段名或字段的表点字段名称(tablename.fieldname)。如果列名有已使用别名('select foo as bar from…'),使用别名代替列名。如果未定义,则检索第一个字段。

您只使用表名贡献者,因此您需要指定单个字段或限制您的选择仅为您想要的字段

$contributors[] = mysql_result($result, $i, 'contributors.name');

$result = mysql_query("
    SELECT contributors.* 
    FROM albums 
    LEFT JOIN contributors ON albums.album_id = contributors.album_id 
    ORDER BY albums.datum DESC; 
") or die(mysql_error());