consecutive rows

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alix
Forum Commoner
Posts: 42
Joined: Thu Nov 18, 2004 8:41 am

consecutive rows

Post by alix »

i have many of rows in a table.. all of them have a number identifyer thats auto incremented. Im trying to make a script that each time the script is called it selects one row then pulls the info from it.. then the next time its called, it pulls the next row and moves on down the list in order. So it'll rotate through each of the rows in the table. The problem is that the id number isnt consecutive because some rows have been removed. I created a table that the script will store the last row accessed and then the next time its called it can move on. Whats the best way to add 1 to the last row called.. check to see if it exsists, if not add 1 more to that number check to see if its there.. if so call the information and move on with the rest of the script?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

use the limit clause (MySQL)
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

in addition to feyd's post

you won't be adding 1 to the last row called
you'll be selecting the next record where id > that record

using limit 1, like suggested above
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I was actually suggesting a slightly different route: LIMIT 1, {row_number}, which would allow for the order in which the records come to be chosen and dictated by the rest of the query.
Post Reply