在PHP中连接表时丢失数据
我加入了两个表在PHP中连接表时丢失数据,php,sql,Php,Sql,我加入了两个表images和post。只要我在post中有一个空行,我的脚本就可以工作,并且在删除它时停止工作。请帮忙 邮政表格: id title 1 post 2 post2 图像表: id img post_id 1 fgh.jpg 2 2 fhhj.jpg 2 以下是我的SQL: if ($stmt = $con->prepare(" SELECT p.*,i.img,title,id from post AS p JOIN image
images
和post
。只要我在post
中有一个空行,我的脚本就可以工作,并且在删除它时停止工作。请帮忙
邮政表格:
id title
1 post
2 post2
图像表:
id img post_id
1 fgh.jpg 2
2 fhhj.jpg 2
以下是我的SQL:
if ($stmt = $con->prepare(" SELECT p.*,i.img,title,id
from post AS p JOIN images AS i ON i.post_id= p.id ")) {
如果要从表“Post”中选择其对应行在表“Images”中不存在的行,请使用左联接,如下所示:
if ($stmt = $con->prepare(" SELECT p.*,i.img,title,id
from post AS p LEFT JOIN images AS i ON i.post_id= p.id ")) {