dsc862009 2014-08-06 20:38
浏览 31

从两个表上的JOIN查询检索到的数组上的错误

hope my title is clear. I am trying to retrieve results from two tables. So I want everything (hence *) from the table called 'albums'. and I want only all matching (with album_id) results from table 'contributors'.

$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');}

but i get a list of similar errors:

contributor not found in MySQL result index ...

Joining of two tables is totally new to my, and maybe it's not the way to go, but maybe it's just a plain simple error in this code, anyway, I'm stuck here,

all help is welcome thx S

  • 写回答

1条回答 默认 最新

  • douxi3085 2014-08-06 20:59
    关注

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

    FIELD

    The name or offset of the field being retrieved.

    It can be the field's offset, the field's name, or the field's table dot field name (tablename.fieldname). If the column name has been aliased ('select foo as bar from...'), use the alias instead of the column name. If undefined, the first field is retrieved.

    You're just using the table name contributors, so either you need to specify a single field or limit your select to only the fields you want

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

    OR

    $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());
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?