php - 如何在 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 降序输出请帮帮我
解决方案
所以你首先想要具有最高 id 的条目?那么它应该是这样的:
Select * from my_data where id between ($id+1) and ($id+4) ORDER BY id DESC
推荐阅读
- angular - 向我的自定义离子组件添加功能颜色属性
- php - 在没有迁移的情况下向 Eloquent 模型添加一列 -PHP
- python - Django import_export 在提交时解码 ascii 代码?
- oop - 封装的真正优势是什么,为什么它特定于 OOP
- delphi - 如何将指针转换为 IObjectiveC 接口?
- c++ - 当函数参数将类型从 int 更改为 unsigned 时,性能差异巨大
- c# - 如何判断某物是否是 IEnumerable<>?
- php - Composer 强制安装包忽略依赖版本
- java - 正则表达式 - 无法将西里尔字符与 \w 匹配
- sql - 交叉连接 2 选择语句 (SQL)