基于行的动态导航 [英] Dynamic navigation based on rows
问题描述
我正在创建一个产品评估系统,要查看特定产品,请使用以下URL:www.example.com/category?product_id=1
.每个页面上的导航只是当前的product_id
+ 1/-1,因此,如果您要查看我刚才给出的示例URL,则返回到product_id=0
,然后转到product_id=2
.一切正常,直到我从数据库中删除产品,并且product_id
不再存在,它所在的URL才显示空白页.
I'm creating a product rating system, to view a specific product, the following URL is used: www.example.com/category?product_id=1
. The navigation on each page is simply the current product_id
+ 1 / -1, so if you were to view the example URL I just gave, back would go to product_id=0
and next would go to product_id=2
. This works fine, until I delete a product from the database, and that product_id
no longer exists, the URL it was at just displays a blank page.
将这种导航转换为动态导航以使其转到下一个product_id
而不是一组product_id
的正确方法是什么?
What would be the correct way to turn this navigation into a dynamic one, so that it goes to the next product_id
rather than a set product_id
?
推荐答案
的伪代码:
next_product_id = query_value(从产品WHERE ID中选择SELECT ID> $ this_product_id ORDER BY ID ASC LIMIT 1")
next_product_id = query_value("SELECT id FROM product WHERE id > $this_product_id ORDER BY id ASC LIMIT 1")
previous_product_id = query_value(从产品WHERE ID< $ this_product_id ORDER BY ID DESC LIMIT 1中选择ID")
previous_product_id = query_value("SELECT id FROM product WHERE id < $this_product_id ORDER BY id DESC LIMIT 1")
这篇关于基于行的动态导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!