首页 > 解决方案 > 如何在 mysql 中使用 order 和 between

问题描述

我在这个 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 降序输出请帮帮我

标签: phpmysqlsql-order-bybetween

解决方案


所以你首先想要具有最高 id 的条目?那么它应该是这样的:

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

推荐阅读