douzhi9395 2015-12-13 18:02
浏览 36
已采纳

PHP和SQL INSERT JOIN 2表,标准错误

$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());

This is the error I get when I execute the code in my web page:

enter image description here

What I'm trying to do is select only the 'rentings' where the personId = $personId, (as the current page is a page for each individual person), and display only those 'rentings'. Also in the code which I haven't posted I'm displaying data about the property which is related to that rent, hence why I'm trying to join the renting and properties table with propertyId so that I call the correct property's details off the database.

  • 写回答

1条回答 默认 最新

  • du13932014807 2015-12-13 18:07
    关注
    $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());
    

    First of all try this, the where condition has to be after the joins. If there are other problems I will edit the answer

    The next problem is that you are joining the same table, but you are joining it in an external field. A quick fix, if I am supposing correct, is that you wrongly joined with an unwanted table:

    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'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题