Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 7th, 2006, 3:58 AM   #1
TecBrain
Hobbyist Programmer
 
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5 TecBrain is on a distinguished road
Next and Previous Record

I need some guidance here, am working on a catalogue system, I thought of adding next product and previous product in the back end so that the admin will have
more flexibilities, but am kind of out of ideas, the problem that I cant use the product_key coz , what I mean is this if i have 5 products and delete product 3:

Product_id = 1
Product_id = 2
Product_id = 3
Product_id = 4
Product_id = 5

after ---

Product_id = 1
Product_id = 2
Product_id = 4
Product_id = 5

so i thought of creating a loop and control the next and previous by adding or subtracting 1, but this wont work, anyone got an idea to get me started.
Thanks.
__________________
Personal Portfolio
TecBrain Support Forum
Linux VS Windows ... Dont Even Think of it ..
Distribution: Slackware
if (OS==Linux) return success
There are 10 kinds of people, those who can read binary numbers and those who can't.
TecBrain is offline   Reply With Quote
Old Apr 7th, 2006, 7:33 AM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
You need to be clearer on what "next" and "previous" are in relation to. A set returned by a query? There are no real "next" and "previous" anything without specifying context.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Apr 7th, 2006, 7:34 AM   #3
Mocker
Hobbyist Programmer
 
Mocker's Avatar
 
Join Date: Oct 2005
Location: Indiana
Posts: 224
Rep Power: 0 Mocker is an unknown quantity at this point
Send a message via AIM to Mocker
might be an easier way, but you could do something like

previous, SELECT * FROM product_table WHERE product_id < var_previousID ORDER BY product_id DESC LIMIT 1


next, SELECT * FROM product_table WHERE product_id > var_previousID ORDER BY product_id ASC LIMIT 1

that should just select one record, either the next greatest product id, or next smallest
__________________
#programmingforums relay - http://thegupstudio.com/cgi-bin/pforelay.cgi
freelance scripts - http://ryanguthrie.com/index.html
Mocker is offline   Reply With Quote
Old Apr 8th, 2006, 6:32 AM   #4
ASHORY
Programmer
 
ASHORY's Avatar
 
Join Date: Dec 2004
Location: Egypt
Posts: 30
Rep Power: 0 ASHORY is on a distinguished road
Send a message via ICQ to ASHORY Send a message via MSN to ASHORY Send a message via Yahoo to ASHORY
go here it may help you .

http://www.phpfreaks.com/tutorial_ca...Pagination.php
__________________
"^Ahmed.SHOukRY^"
http://www.ashory.741.com
ASHORY is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:16 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC