perpage = 2
totalposts = db(db.post.id > 0).count()
totalpages = totalposts / perpage
page = int(request.vars.page) if request.vars.page else 1
limit = int(page - 1) * perpage
posts = db(db.post.id > 0).select(orderby=~db.post.id,
limitby=(limit+1,limit+perpage+1))

I changed just your last line. Hope it helps you...

On Wed, Nov 4, 2009 at 11:39 PM, Mengu <whalb...@gmail.com> wrote:

>
> sorry massimo, i didn't understand again. i guess i need some rest.
>
> can you explain me the web2py way of pagination? my algorithm is as
> the following:
>
> 1) set a limit to display per page.
> 2) get the total posts.
> 3) get the total pages by totalposts/perpage
> 4) get page via request.vars.page if exists or it is 1.
> 5) offset is (page - 1) * perpage
> 6) get the query (offset, perpage)
>
> as i have mentioned, i have removed the (lmax - lmin) statement from
> LIMIT query and made it ' LIMIT %i OFFSET %i' % (lmax, lmin) (sql.py
> line 2846) so this logic works smoothly. please let me understand
> yours.
>
> sincerely
> Mengu
>
> On Nov 4, 9:21 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
> > All this does is when you do
> >
> > for row in db(...).select(limitby=(2,10)): print row
> >
> > it will skip the first two rows and loop over the remaining 10-2=8
> > rows.
> >
> > Massimo
> >
> > On Nov 4, 11:04 am, Mengu <whalb...@gmail.com> wrote:
> >
> > > hi massimo,
> >
> > > i didn't undertand the pagination logic here. could you please
> > > explain?
> >
> > > sincerely
> > > Mengu
> >
> > > On Nov 4, 5:30 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
> >
> > > > limitby=(a,b)
> >
> > > > returns rows[i] for a <= i < b
> >
> > > > On Nov 4, 3:30 am, Mengu <whalb...@gmail.com> wrote:
> >
> > > > > hi everyone.
> >
> > > > > i have a problem with paginating my results. i guess i didn't
> > > > > understand the logic in limitby.
> >
> > > > > normally an sql query SELECT * FROM post LIMIT 2 OFFSET 0 displays
> the
> > > > > first 2 results. And I can get the first 2 records with db
> > > > > (db.post.id>0).select(limitby(0,2)). so limit is 2 and offset is
> 0.
> >
> > > > > however the problem is, this query fails:
> > > > > db(db.post.id>0).select(limitby(2,2)). in this query the limit is
> 2
> > > > > and the ofset is 2 either. however it doesn't return select * from
> > > > > post limit 2 offset 2 but it returns select * from post limit 0
> offset
> > > > > 2 because in sql.py 2846 limit is lmax - lmin and offset is lmin. i
> > > > > have edited that line as sql_o += ' LIMIT %i OFFSET %i' % (lmax,
> lmin)
> > > > > and it is working as expected. now my pagination is working.
> >
> > > > > here is my codes for pagination:
> > > > > perpage = 2
> > > > > totalposts = db(db.post.id > 0).count()
> > > > > totalpages = totalposts / perpage
> > > > > page = int(request.vars.page) if request.vars.page else 1
> > > > > limit = int(page - 1) * perpage
> > > > > posts = db(db.post.id > 0).select(orderby=~db.post.id,
> limitby=(limit,
> > > > > perpage))
> >
> > > > > please let me know if there's another page for doing this.
> >
> > > > > sincerely
> > > > > Mengu
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to