duanmibei1929 2015-01-26 11:50
浏览 13
已采纳

从多个表中选择行失败

i have the following code.

i already try'd some sulotions from the search option, but nothing helped.

all tables have a row called: user_id with data in it, but still the query gives false The $user variable has the value 29 and in my tables look like this:

+---------+---------+-------+-----------+
+ id      | user_id | jaar  + kenmerk   |
+---------+---------+-------+-----------+
+ 1       | 29      | 2015  + standaard |
+---------+---------+-------+-----------+



    $query = "SELECT buitenklimaat.user_id, kasklimaat.user_id, watermangement.user_id, energie.user_id FROM buitenklimaat, kasklimaat, watermangement, energie WHERE user_id = ".$user." AND kenmerk = 'standaard' AND jaar = ".date("Y")."";

    $result = mysqli_query($conn, $query);

    if($result === false) {
        echo 'Query failed';
        die();
    }
    else {
         // do something
    }
  • 写回答

2条回答 默认 最新

  • 普通网友 2015-01-26 11:59
    关注

    If the field user_id exists in more than one table, you need to prefix the field with the table name in your where clause, too. Otherwise your database will not know in which table it should look for the user_id field. But even after you fixed this error the query will probably not return what you want it to. Have a look at some SQL tutorials that cover the join syntax.

        $query = "SELECT buitenklimaat.user_id, kasklimaat.user_id, watermangement.user_id, energie.user_id FROM buitenklimaat, kasklimaat, watermangement, energie WHERE <TABLENAME MISSING>.user_id = ".$user." AND kenmerk = 'standaard' AND jaar = ".date("Y")."";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用