gpt4 book ai didi

php - 我如何在mysql中使用order和between

转载 作者:行者123 更新时间:2023-11-29 03:18:10 25 4
gpt4 key购买 nike

我在这个 mysql 代码中使用 Order 和 Between 时遇到问题:

<?php 

$connection = mysqli_connect("localhost","my_user","my_password","my_db");
$id = $_GET["id"];
$query = "Select * from my_data where id between ($id+1) and ($id+4)";
$result = mysqli_query($connection,$query);
while ($row = mysqli_fetch_assoc($result)) {

$array[] = $row;
}
header('Content-Type:Application/json');
echo json_encode($array);?>

我想按id降序输出请帮助我

最佳答案

所以您希望 ID 最高的条目优先?那么它应该是这样的:

Select * from my_data where id between ($id+1) and ($id+4) ORDER BY id DESC

关于php - 我如何在mysql中使用order和between,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50833437/

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