gpt4 book ai didi

php - MySQL 根据之前的查询选择行

转载 作者:行者123 更新时间:2023-11-29 01:39:08 26 4
gpt4 key购买 nike

$clicks = mysqli_real_escape_string($conn,$_POST['clicks']);
$modifier = 10*$clicks;

$result = mysqli_query($conn,"SELECT * FROM posts ORDER BY freshness LIMIT $modifier,10");

while($row = mysqli_fetch_assoc($result)){
$posts[] = $row;
}

$result2 = mysqli_query($conn,"SELECT * FROM comments ORDER BY time WHERE ????");

while($row2 = mysqli_fetch_assoc($result2)){
$comments[] = $row2;
}

对于 $result2,我如何选择 10 个帖子 ID 中每一个的 WHERE(即 $row['id'])来自 $结果?否则我会不必要地选择表格中的每一条评论。

最佳答案

为什么不在一个查询中完成这一切?

 $modifier = 10*$clicks;

$query = "SELECT *
FROM posts
INNER JOIN comments
ON posts.id = comments.post_id
ORDER BY posts.freshness
LIMIT '$modifier'";

关于php - MySQL 根据之前的查询选择行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30699305/

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