Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP中连接表时丢失数据_Php_Sql - Fatal编程技术网

在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 ")) {