gpt4 book ai didi

php - 查询指示不希望的事件

转载 作者:搜寻专家 更新时间:2023-10-30 23:28:58 26 4
gpt4 key购买 nike

我想做一个 facebook 风格的 friend 搜索部分。但我只想把我的 friend 放在 friend table 上。我的表在这个 DEMO .

    $result = mysqli_query($this->db,"        
SELECT U.username
, U.userid
, U.userfullname
, UT.username
, UT.userid
, UT.userfullname
, F.role
FROM friends F
JOIN users U
ON F.userone = U.userid
JOIN users UT
ON F.usertwo = UT.userid
WHERE U.username Like '%$key'
OR UT.userfullname Like '$key%'
OR UT.username Like '$key%'
OR UT.userfullname Like '%$key'
OR UT.username Like '$key'
OR UT.userfullname Like '$key'
AND F.userone = '$uid'
AND (F.role='fri' OR F.role = 'flwr')
ORDER
BY F.userone
LIMIT 10
") or die(mysqli_error($this->db));
while($row=mysqli_fetch_array($result,MYSQLI_ASSOC)) {
$data[]=$row;
}
if(!empty($data)) {
return $data;
}

搜索者的用户 ID($uid) 是 1 并且 key 是例如 aziz 因为 azizs 的 userid2 如果你检查 friend 表 userone(1) 和 usertwo(2 ) 是那里的 friend 。我们怎么知道他们是 friend ,因为 rolefri。您可以在 DEMO 中看到它 页面也。

问题来了!问题是当 $uid(1) 搜索他/她的 friend 时,查询也显示 role ='me' 但我只想显示 F.role='fri' OR F.role = 'flwr' 。我的查询有什么问题。

最佳答案

怎么样...

SELECT U.username
, U.userid
, U.userfullname
, UT.username
, UT.userid
, UT.userfullname
, F.role
FROM friends F
JOIN users U
ON F.userone = U.userid
JOIN users UT
ON F.usertwo = UT.userid
WHERE (
U.username Like '%$key'
OR UT.userfullname Like '$key%'
OR UT.username Like '$key%'
OR UT.userfullname Like '%$key'
OR UT.username Like '$key'
OR UT.userfullname Like '$key'
)
AND F.userone = '$uid'
AND F.role IN('fri','flwr')
ORDER
BY F.userone
LIMIT 10

请注意,您仍然可以使用这种方法进行注入(inject)。

关于php - 查询指示不希望的事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52027016/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com