PHP/MYSQL 查询:获取结果上方和下方的行!
我不知何故需要一种方法来实现以下目的:
用户位于某个博客页面现在我想让他能够移动:
到下一个更受欢迎的页面或到下一个不太受欢迎的页面。意思是,像这样:(
[PAGE 5] | [PAGE 3 (User is here)] | [PAGE 2]
其中第 1 页 = 最受欢迎,第 3 页 = 最不受欢迎)。我的 MySQL 表如下所示:
[ID] [VIEWS]
[1] [1000]
[2] [2560]
[3] [3200]
[4] [200]
[5] [4000]
我的问题是特定的查询。在本例中,唯一给定的变量是 ID:2。也许你可以帮我。如果您需要更多信息,请告诉我。 (我只需要两个邻居。不需要第 4 页等。)
编辑:@Trevor 不,抱歉我不能。我改变了这个例子,使它更清楚。
I somehow need a way for the following:
User is located at some blog page Now I want to give him the ability to move either:
To the next more popular page OR to the next less popular page. Means, something like this:
[PAGE 5] | [PAGE 3 (User is here)] | [PAGE 2]
(Where Page 1 = most popular, Page 3 = least popular). My MySQL Table looks like this:
[ID] [VIEWS]
[1] [1000]
[2] [2560]
[3] [3200]
[4] [200]
[5] [4000]
My problem is the specific query. The only given variable is the ID: 2 in this case. Maybe you can help me out. Just tell me if you need further informations.
(I only need the two neighbours. Page 4 etc. would not be needed.)
Edit: @Trevor No, sorry I cant. I changed the example so its more clearly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
注意:根据各种评论,@mellamokb 的答案比我的好。我会删除这个答案,但由于它被接受而无法删除。
NOTE: As worked out in the various comments, @mellamokb's answer is better than mine. I would delete this answer but am unable to since it was accepted.
上一页:
下一页:
For previous page:
For next page:
或者
or
三个查询:
使用本地“视图”:
并且,确保您在视图上有索引。
Three queries:
Using local "Views":
And, make sure you have an index on Views.