Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.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 mysql中使用内部联接和concat()操作的查询中出现问题_Php_Mysql_Inner Join - Fatal编程技术网

Php mysql中使用内部联接和concat()操作的查询中出现问题

Php mysql中使用内部联接和concat()操作的查询中出现问题,php,mysql,inner-join,Php,Mysql,Inner Join,我有两张桌子: sk_accounts //details of user acnt\u用户\u id acnt\u fname//名字 acnt_lname acnt\u配置文件\u图片 acntúU成员úU类 等等 sk_following //table containing details of users who are following others 身份证 flwing_follower_id//被其他跟随者跟随的用户的id flwing_跟随用户id 以

我有两张桌子:

sk_accounts      //details of user
  • acnt\u用户\u id
  • acnt\u fname//名字
  • acnt_lname
  • acnt\u配置文件\u图片
  • acntúU成员úU类
  • 等等

     sk_following   //table containing details of users who are following others
    
  • 身份证

  • flwing_follower_id//被其他跟随者跟随的用户的id
  • flwing_跟随用户id
  • 以下日期

    我想基于以下Mysql代码显示跟随者的详细信息。不幸的是,即使有3行,它也返回零行。我的查询如下:

    $query_following = "SELECT sk_following.flwing_following_user_id, 
    sk_accounts.acnt_fname,
    sk_accounts.acnt_lname,
    sk_accounts.acnt_member_class,
    sk_accounts.acnt_profile_picture
    FROM sk_following 
    INNER JOIN sk_accounts 
    WHERE sk_following.flwing_follower_id='$id' AND        sk_accounts.acnt_user_id=sk_following.flwing_following_user_id AND CONCAT(sk_accounts.acnt_fname,' ',sk_accounts.acnt_lname)='$name'";
    $result_following = mysql_query($query_following);
    $count_following = mysql_num_rows($result_following);
    echo $count_following;
    
注意:$id和$name包含值
请帮助我。提前感谢。

如果看不到示例数据和所需输出,很难完全理解,但是您的加入是否应该在flwing_follower_id上,而不是flwing_follower_用户id上

SELECT sk_following.flwing_following_user_id,
    sk_accounts.acnt_fname,
    sk_accounts.acnt_lname,
    sk_accounts.acnt_member_class,
    sk_accounts.acnt_profile_picture 
FROM sk_following 
    INNER JOIN sk_accounts ON sk_accounts.acnt_user_id=sk_following.flwing_follower_id 
WHERE sk_following.flwing_follower_id='$id' 
    AND CONCAT(sk_accounts.acnt_fname,' ',sk_accounts.acnt_lname)='$name'
祝你好运。

试试这个

"SELECT sk_following.flwing_following_user_id,
sk_accounts.acnt_fname,
sk_accounts.acnt_lname,
sk_accounts.acnt_member_class,
sk_accounts.acnt_profile_picture 
FROM sk_following
LEFT JOIN sk_accounts ON sk_accounts.acnt_user_id=sk_following.flwing_following_user_id
WHERE sk_following.flwing_follower_id='$id'
AND CONCAT(sk_accounts.acnt_fname,' ',sk_accounts.acnt_lname)='$name'";

这可能会对您有所帮助。

@sdespont抱歉,我不知道格式。您能否确认以下用户id是对acnt用户id字段表的引用?@sdespont Ya,我在另一个上下文中使用了此查询,但没有使用concat()尝试一个接一个地应用WHERE子句..你会发现哪里出了问题..@s响应我检查了WHERE子句,它有一些错误。这是我的错误我想在一个div中显示上述所有数据。使用左连接,因为它比内部连接好。看到@Anaz A了吗?你明白了吗?我认为使用左连接更好。我还使用了更多的左连接,然后是内连接。