Hi,

I'm quite new to web2py and currently building a simple application: a
message board, listing latest 20 messages by index(). For earlier
messages, there is a  self-submitting form to enter page number (20
message each page) to go to, and after submitting the form, redirects
to that page. Here is the question on the self-submitting form:
nothing changed (always showing the 1st page) whatever number is input
into the form. Controller as follows:

def index():
    page_no=1
    entries=db(db.whoelse.id > 0).count()
    messages=db((db.whoelse.id>(entries-20)) &
(db.whoelse.id<=entries)).select(db.whoelse.ALL,
orderby=~db.whoelse.created_on)

    if request.vars.page_no:
        if request.vars.page_no>(entries/20+1):
            redirect(URL(r=request, f='index'))
        else:
            redirect(URL(r=request, f='gotopage')
    form=crud.create(db.whoelse,
next=URL(r=request,args=1),message='Your message is posted')
    return dict(messages=messages, entries=entries,
form=form,page=page_no)

def gotopage():
    entries=db(db.whoelse.id > 0).count()
    messages=db((db.whoelse.id>(entries-request.vars.page_no*20)) &
(db.whoelse.id<=((entries-
(request.vars.page_no-1)*20)))).select(db.whoelse.ALL,
orderby=~db.whoelse.created_on)

    form=crud.create(db.whoelse,
next=URL(r=request,args=1),message='Your message is posted')
    return dict(messages=messages, entries=entries, form=form,
page=request.vars.page_no)
------------------------------------------
and corresponding view part:
 <h5>{{=page}}/{{=entries/20+1}} Pages&nbsp;&nbsp;&nbsp;&nbsp;Go to
page:<form><input name="page_no" />  <input type="submit" /></form></
h5>
------------------------------------------

Any reply will be appreciated.

Spring

Reply via email to