Jump to content

Archived

This topic is now archived and is closed to further replies.

brighton

linking the results in different pages

Recommended Posts

Here is the question:
I can return my results from the database as a list and each result on the list have a detail info page where I can go when I click on the result. I want to make next / previous page links from these detail pages that will go from one detail page to another without returning back to the list.
Do you have any idea how to do that?

Share this post


Link to post
Share on other sites
Hello,

On the details page you would have id for the current item shown.

Fire a query from the database which will give you id of previous item from the list and next item from the list.

You will have to take care that these queries should be sorted using the same field which you have used in main page query...

For ex: suppose your main results page has a query like this

$sql = "select * from products where category ='1' order by product_id";

in your details page , you fire 2 queries

//for previous id
$prev_sql = "select * from products where category ='1' and product_id < '".$id."'order by product_id limit 1";

this will give you id of the previous item

//for next id
$next_sql = "select * from products where category ='1' and product_id > '".$id."'order by product_id limit 1";

this will give you id of the next item

When u have both previous and next id's , you can show hyperlinks like this

<a href='details.php?id=<?php echo $previous_id;?>'> and
<a href='details.php?id=<?php echo $next_id;?>'>

hth

Share this post


Link to post
Share on other sites
Thank you very much. It worked.

For the ones who wants to use this, just remember to order the previous link query descending.

Thanks again!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.