gpt4 book ai didi

php - Mysqli查询随机选择

转载 作者:行者123 更新时间:2023-11-29 22:10:47 24 4
gpt4 key购买 nike

如何随机化我的选择查询?

SELECT *
FROM posts p
INNER JOIN friends f ON (
(
p.from_user = f.user1
OR p.from_user = f.user2
)
AND (
f.user1 = '$ownid'
OR f.user2 = '$ownid'
)
AND f.accepted
)
WHERE p.from_user != '$ownid'
ORDER BY p.posted_time

是的,我想保留查询的情况,并按时间排序,但此时随机原因使其生成 block 。

编辑:这里是我的表格,以便更好地理解

enter image description here

最佳答案

您可以考虑使用 PHP rand 函数:rand():

rand(0,$sql_num_rows)

该函数比mysql rand函数会提高性能。

关于php - Mysqli查询随机选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31706532/

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