PHP和SQL INSERT JOIN 2个表的条件错误

PHP和SQL INSERT JOIN 2个表的条件错误,php,mysql,Php,Mysql,这是我在网页中执行代码时遇到的错误: 我试图做的是只选择“rentings”,其中personId=$personId,(因为当前页面是针对每个人的页面),并且只显示那些“rentings”。另外,在我没有发布的代码中,我显示了与该租金相关的物业数据,因此我尝试将renting and properties表与propertyId连接,以便从数据库中调用正确的物业详细信息 $rentingsquery = "SELECT * FROM TBL_rentings WHERE personId='

这是我在网页中执行代码时遇到的错误:

我试图做的是只选择“rentings”,其中
personId=$personId
,(因为当前页面是针对每个人的页面),并且只显示那些“rentings”。另外,在我没有发布的代码中,我显示了与该租金相关的物业数据,因此我尝试将renting and properties表与propertyId连接,以便从数据库中调用正确的物业详细信息

$rentingsquery = "SELECT * FROM TBL_rentings WHERE personId='$personId'
JOIN TBL_rentings ON TBL_properties.propertyId = TBL_rentings.propertyId
JOIN TBL_people ON TBL_rentings.personId = TBL_people.personId";
$rentingsResult=mysql_query($rentingsquery) or die ("Query to get data from TBL_properties failed: ".mysql_error());
首先,请尝试这样做,连接之后必须有where条件。 如果还有其他问题,我将编辑答案

下一个问题是,您正在连接同一个表,但是您正在外部字段中连接它。如果我认为正确的话,一个快速修复方法是您错误地加入了一个不需要的表:

$rentingsquery = "SELECT * FROM TBL_rentings
    JOIN TBL_rentings ON TBL_properties.propertyId = TBL_rentings.propertyId
    JOIN TBL_people ON TBL_rentings.personId = TBL_people.personId
    WHERE personId='$personId'";
    $rentingsResult=mysql_query($rentingsquery) or die ("Query to get data from TBL_properties failed: ".mysql_error());

请不要使用文本截图,特别是当它们是错误描述时。人们在谷歌上搜索这些内容并使用图像会极大地妨碍可查找性,使这个问题无法为更广泛的受众所用。很抱歉,我无法编辑答案,因为代码中有一些奇怪的东西,您正在将
rentings
rentings
一起加入到properties和rentings的字段中。join中的表不应该是
TBL\u properties
?将代码更改为:join TBL\u rentings.propertyId=TBL\u properties.propertyId会出现此错误;您应该在where子句中指定personId。我的答案又一次更新了。我不知道你的表是如何构造的,它应该可以工作,你能粘贴(不是截图)你正在使用的实际代码,表结构和错误吗?是的,修复了它!!非常感谢!
SELECT * FROM TBL_rentings
JOIN TBL_properties ON TBL_properties.propertyId = TBL_rentings.propertyId
JOIN TBL_people ON TBL_rentings.personId = TBL_people.personId
WHERE TBL_rentings.personId='$personId'