Anthony, Thanks for the tips.
I have a table which I insert data from the internet, just 4 records. Before inserting though I need to get the last 5 rows of data from these 4 fields and do a calculation with them. Then when I insert the data I add one more field making it a total of 5 fields I am inserting into the db. These 5 fields exist already so nothing odd there. My main issue is just getting the last 5 records from the db. Is there a better way to get that data with the DAL? It kind of appears to me that I could possibly use limitby to get these as well? Thanks, Tom On Tuesday, May 20, 2014 9:48:23 AM UTC-4, Anthony wrote: > > Note, there is no guarantee that the records in the db at any given time > have sequential values in the ID field (e.g., when you delete a record, the > value of its ID is then absent from the sequence of IDs). > > Can you explain in more detail what you are actually trying to do? > > Anthony > > On Tuesday, May 20, 2014 9:32:27 AM UTC-4, Tom Russell wrote: >> >> Thanks for the comments. I read Chapter 6 which is where I got the bit of >> code to access the records. Specifically the fetching a row section. >> >> I can ensure that there is records with those id's. Its a script that >> grabs data off from the internet and inserts that data into that table. >> Then I grab the last 5 records including the one it is grabbing to do a >> calculation on it. >> >> It is not too clear in the book how I should be getting a record by the >> id is what I think my problem is. >> >> Thanks, >> >> Tom >> >> On Tuesday, May 20, 2014 4:53:13 AM UTC-4, Johann Spies wrote: >>> >>> On 19 May 2014 22:06, Tom Russell <tsrda...@gmail.com> wrote: >>> >>> I have some records in my db that I need to access to get them and >>>> perform some calculations on. >>>> >>>> My code to access the records is: >>>> >>>> rows = db(db.voltrin.id > 0).count() >>>> >>> >>> Let us assume rows = 100 at this point. >>> >>>> >>>> currentrow = rows - 4 >>>> >>> >>> currentrow = 96 >>> >>> >>>> >>>> for x in range(currentrow, rows): >>>> >>> range(96, 100) >>> >>>> record = db.voltrin(db.voltrin.id==x) >>>> >>> record = db.voltrin(db.voltrin.id = >>> 96).select(whateverfieldsyouwantoworkwith) >>> >>> >>> >>>> Is this the right way to access the record at a given id? >>>> >>>> No. >>> >>> I would suggest you read Chapter 6 in the web2py book ( >>> http://web2py.com/book). >>> >>> Just a comment about your code: there is no way you can ensure in the >>> above example that there will be an id==96 in that database. >>> >>> Regards >>> Johann >>> -- >>> Because experiencing your loyal love is better than life itself, >>> my lips will praise you. (Psalm 63:3) >>> >> -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.