Overview of features
Home
Read this first
About
web2py is 100% free
Download
Start learning web2py today
Documentation
Authors and contributors
Staff
Affiliated companies
Support
Edit page
Title:
Security Code:
Body:
(use
this
wiki markup)
Based on : http://mdp.cti.depaul.edu/AlterEgo/default/show/63 This example improves on the previous one by calculating the total number of records beforehand. It provides positional feedback to the user, and avoids displaying an empty list at the end. def show_records(): totalrecs = db.executesql('select count(*) from table')[0][0] # number of records in table (for example) showlines = 25 # number of records per page if len(request.args): page=int(request.args[0]) else: page=0 query=db.table.id>0 ### for example (all records in table) rows=db(query).select(limitby=(page,page+showlines)) backward=A('<< previous',_href=URL(r=request,args=[page-showlines])) if page else '<< previous' forward=A('next >>',_href=URL(r=request,args=[page+showlines])) if totalrecs>page+showlines else 'next >>' nav= "Showing %d to %d out of %d records" % (page+1, page+len(rows), totalrecs) return dict(rows=rows,backward=backward,forward=forward, nav=nav)