You seem to be incrementing 'counter' in the session (the counter is
user session specific then).
Also, you are using session.one_counter/two_counter/three_counter,
without having initialized it. Is that a typo?
________________________________________
Kiran Subbaraman
http://subbaraman.wordpress.com/about/
On Sat, 27-02-2016 6:35 AM, Joe wrote:
I am trying to use session.counter to count clicks on images on a page.
My problem is that my session.counter is not counting...
I am doing something wrong, not sure exactly what.
I am pretty sure the issue is the/if image.id == 1/
I'd appreciate some help with this.
*Controller:*
def index():
images = db().select(db.image.ALL, orderby=db.image.id)
return dict(images=images)
def show():
image = db.image(request.args(0,cast=int)) or redirect(URL('index'))
one_counter = []
two_counter = []
three_counter = []
if image.id == 1:
session.counter = (session.counter or 0)+1
one_counter=session.one_counter
elif image.id == 2:
session.counter = (session.counter or 0)+1
two_counter=session.two_counter
elif image.id == 3:
session.counter = (session.counter or 0)+1
three_counter=session.three_counter
return dict(image=image)
def download():
return response.download(request, db)
*View:*
show:
<h3>{{=0 if session.one_counter is None else session.one_counter}}</h3>
<h3>{{=0 if session.two_counter is None else session.two_counter}}</h3>
<h3>{{=0 if session.three_counter is None else
session.three_counter}}</h3>
--
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
<mailto:web2py+unsubscr...@googlegroups.com>.
For more options, visit https://groups.google.com/d/optout.
--
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.