|
-
Jul 19th, 2009, 01:35 PM
#1
Thread Starter
Lively Member
[RESOLVED] links to previous and next record
A very common issue, but I couldn't find solution. Please help!
I have a table with an auto_increment id. Since records get deleted, the id number is not continuous or even sorted. I need to display contents of each record one at a time in a page with links to next and previous record at the bottom.
How do I do this?
Save trees, avoid plastics, say no to zoo, go veg, recycle as much, live holistic
-
Jul 19th, 2009, 10:02 PM
#2
Re: links to previous and next record
How are you displaying the records on an html page or flash page? The reason I ask is when viewing the contents of a database in phpdev one record = one row in the database. All the available record will be visible.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Jul 19th, 2009, 11:30 PM
#3
Re: links to previous and next record
 Originally Posted by sridharao
I have a table with an auto_increment id. Since records get deleted, the id number is not continuous or even sorted. I need to display contents of each record one at a time in a page with links to next and previous record at the bottom.
How do I do this?
Off the top of my head:
There are two ways to do this.
In the first case you have already selected a cross-section of records (perhaps even cached them into a view. Well done!) and thus you know all of the IDs when you display the list of records. When you enter a single record, pass the previous and next IDs as parameters.
This is the most efficient method. However...
In the second case (which will inevitably occur regardless of whether you code for the first case) you are displaying a single record and have no idea what the previous and next records are. In this case you need to execute two SELECT queries to find them. You also need to decide on a sort column and order. If the records are naturally ordered by date, you can get "Newer" and "Older" IDs this way (where ? is the date of the current record):
Code:
# Newer
select id from records where date>? order by date asc limit 1
# Older
select id from records where date<? order by date desc limit 1
(There may be some way of doing it in one query, but I can't think of it right now.)
 Originally Posted by Nightwalker83
How are you displaying the records on an html page or flash page? The reason I ask is when viewing the contents of a database in phpdev one record = one row in the database. All the available record will be visible.
I have no idea what bearing nor relevance this has to the question asked.
-
Jul 19th, 2009, 11:58 PM
#4
Re: links to previous and next record
 Originally Posted by penagate
I have no idea what bearing nor relevance this has to the question asked.
I was thinking it being called from the actual html/flash page!
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Jul 21st, 2009, 08:59 AM
#5
Thread Starter
Lively Member
Re: links to previous and next record
I solved the issue by using the next and previous id's in the links.
Save trees, avoid plastics, say no to zoo, go veg, recycle as much, live holistic
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|