Jump to content


Photo

linking the results in different pages


  • Please log in to reply
2 replies to this topic

#1 brighton

brighton
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 23 May 2006 - 09:04 AM

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?

#2 samshel

samshel
  • Members
  • PipPipPip
  • Advanced Member
  • 837 posts

Posted 23 May 2006 - 09:15 AM

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

Cheers,
SamShel
-----------------------------------------------
--: FUTURE IS LINUX :--
-----------------------------------------------

#3 brighton

brighton
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 23 May 2006 - 11:26 PM

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!





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users