在左连接后不能在for each循环中显示列

zf9nrax1  于 2021-06-17  发布在  Mysql
关注(0)|答案(1)|浏览(287)

我正在我的项目表上运行此查询

SELECT item.*, status.status_id  FROM item LEFT JOIN status ON item.status = status.id

<?php foreach ($itemqedit as $myitem) : ?>
                                        <tr>
                                            <td><?= $myitem['item_desc'] ?></td>
                                            <td><?= $myitem['display'] ?></td>
                                            <td><?= $myitem['brand'] ?></td>
                                            <td><?= $myitem['model'] ?></td>
                                            <td><?= $myitem['spec'] ?></td>
                                            <td><?= $myitem['sn'] ?></td>
                                            <td><?= $myitem['set_name'] ?></td>
                                            <td><img src="items-img/<?= $myitem['item_pic'] ?>" style="width: 50px"></td>
                                            <td><?= $myitem['date_add'] ?></td>
                                            <td><?= $myitem['status_id'] ?></td>
                                            <td><a class="paginate_button current" href="itemedit.php?itmid=<?= $myitem['id'] ?>"> <button class="btn btn-info pull-left" > עריכה</button> </a> </td>
                                        </tr>

查询运行良好,我得到了所需的结果
我还使用这个查询为每个循环运行,我可以显示除 status_id 那是来自 status table
注意:第94行的c:\xampp\htdocs\ch10nb\edititem.php中的未定义索引:status\u id
我做错什么了?在phpmyadmin中,当我运行这个查询时,我没有得到任何错误,我可以看到 status_id 已添加到项目表,但无法显示它。

weylhg0b

weylhg0b1#

尝试添加别名

SELECT item.*
    , status.status_id   AS  status_id
FROM item 
LEFT JOIN status ON item.status = status.id

相关问题