Jump to content

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?
Link to comment
https://forums.phpfreaks.com/topic/10246-linking-the-results-in-different-pages/
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
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.