gpt4 book ai didi

mysql - 从一个表中选择attachment_id,并在另一个表中选择user_id

转载 作者:行者123 更新时间:2023-11-30 00:04:25 24 4
gpt4 key购买 nike

我想从 phpbb_attachments 中选择 5 个随机图像,并显示 phpbb_users 中的作者用户名。

phpbb_attachments:        phpbb_topics_posted:        phpbb_users:

attach_id topic_id user_id topic_id user_id username
1 10 21 10 21 Tom
2 5 53 5 53 Maria
3 15 11 15 11 John

$result = mysqli_query($con,"SELECT * FROM phpbb3_attachments WHERE mimetype = 'image/jpeg' ORDER BY RAND() LIMIT 5");

最佳答案

你可以试试这个:

SELECT att.attach_id,
u.username
FROM phpbb_attachments att
JOIN phpbb_topics_posted t ON (t.topic_id=att.topic_id)
JOIN phpbb_users u ON (u.user_id=t.user_id)
WHERE att.mimetype='image/jpeg'
ORDER BY rand() LIMIT 5

正如上面所说的here ,最好避免 ORDER BY RAND()。寻找一些替代方案。

此外,我只包含您显示的字段,您应该调整它以包含文件位置等字段。

最后但并非最不重要的一点是,您的示例查询引用 phpbb3_attachments,并且示例数据使用不同的名称。您应该相应地进行调整。

希望这有帮助。

关于mysql - 从一个表中选择attachment_id,并在另一个表中选择user_id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24714650/

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