上一个/下一个按钮 sql 查询
我有一个包含以下列的表数据:
|-a-|-b-|-文本-|
|-1-|-1-|-文本-|
|-1-|-2-|-文本-|
|-1-|-3-|-文本-|
|-2-|-1-|-文本-|
|-2-|-2-|-文本-|
|-2-|-3-|-文本-|
|-2-|-4-|-文本-|
例如,我在第三条记录上($current - 粗体),我需要进行 sql 查询以移动到 (2, 1)。
我有如下查询:
$previous = "SELECT a, b FROM `table` WHERE a <= $current_a AND b < $current_b ORDER BY a DESC, b DESC LIMIT 1";
$next = "SELECT a, b FROM `table` WHERE a >= $current_a AND b > $current_b ORDER BY a ASC, b ASC LIMIT 1";
尽管接下来会转到 (2, 4)。
有什么想法吗?
I have a table data with following columns:
|-a-|-b-|-text-|
|-1-|-1-|-text-|
|-1-|-2-|-text-|
|-1-|-3-|-text-|
|-2-|-1-|-text-|
|-2-|-2-|-text-|
|-2-|-3-|-text-|
|-2-|-4-|-text-|
e.g. I am on 3rd record ($current - in bold), I need to make sql query to move to (2, 1).
I have the query as below:
$previous = "SELECT a, b FROM `table` WHERE a <= $current_a AND b < $current_b ORDER BY a DESC, b DESC LIMIT 1";
$next = "SELECT a, b FROM `table` WHERE a >= $current_a AND b > $current_b ORDER BY a ASC, b ASC LIMIT 1";
Though however next goes to (2, 4) instead.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要一个条件来分别处理这两种情况;当 a 值相同和不同时:
您还需要前一项:
You need a condition that handles the two cases separately; when the a values are the same, and when they are different:
You need that for the previous item also: