php - 左连接后无法在 for-each 循环中显示列
问题描述
我正在我的项目表上运行此查询
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
表的列之外的所有列
注意:未定义索引:第 94 行 C:\xampp\htdocs\ch10nb\edititem.php 中的 status_id
我究竟做错了什么?在 phpmyadmin 中,当我运行此查询时,我没有收到任何错误,我可以看到status_id
已添加到项目表中,但我无法显示它。
解决方案
尝试添加别名
SELECT item.*
, status.status_id AS status_id
FROM item
LEFT JOIN status ON item.status = status.id
推荐阅读
- php - 在php中将动态节点添加到xml文件
- reactjs - React 和 Laravel:样式表违反了内容安全策略指令
- java - 为什么 Java 泛型允许通配符的上限高于类型参数的上限?
- java - 如何在前台强制运行批处理或限制批处理不在后台运行
- c# - 更新与其他实体具有多重关系的实体框架实体
- php - 在Window XAMPP的本地系统中设置Yii2项目出现错误
- c# - MasterPage 链接在子文件夹中更改
- ios - 多线程 - Swift 中的 DispatchQueue asyncAfter 延迟
- java - 如何在android studio中制作通话记录器
- python - 解析后我无法将数据写入文件,我不断收到错误字符串索引必须是整数