gpt4 book ai didi

php - mysqli 查询连接有两个唯一键

转载 作者:行者123 更新时间:2023-11-29 12:16:24 25 4
gpt4 key购买 nike

大家好,我的网页中有此查询

 $otherupdates=mysqli_query
($conn,"
SELECT f.sender,f.receiver,f.field,m.name
FROM friend f,members m
WHERE ((f.sender IN ($variable) OR f.receiver IN ($variable))
AND ( f.field='friends' || f.field='fan')
AND ( f.date > '$adatevariable' AND f.sender=m.id))
ORDER BY date DESC LIMIT 16"
);

$variable="'1','2','3'......"; // not important
$adatevariable=date('d', strtotime($today . ' - 2 day'));// not imp

此查询的作用是,获取与 where 子句匹配的所有行,并获取发送者的名称 (f.sender=m.id),但我也希望通过此查询获取接收者的名称,但我不需要另一个查询..

这可能吗,请帮忙

最佳答案

如果您将查询更改为:

select     f.sender,    f.receiver,    f.field,    senders.name AS sender_name,    recievers.name AS recievers_namefrom     friend f    INNER JOIN members senders ON f.sender=senders.id    INNER JOIN members recievers ON f.receiver = recievers.idwhere     (f.sender IN ($variable) or f.receiver IN ($variable))     and f.field IN ('friends', 'fan')     and f.date > '$adatevariable'order by     date desc limit 16

它的作用是允许您访问 members 表两次,一次作为发送者,另一次作为接收者。通过将这些信息加入到您的 friend 表的 senderreciever 字段中,senders 将获得该好友的所有信息。发送者和接收者将拥有接收者的所有信息。

关于php - mysqli 查询连接有两个唯一键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29726398/

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