Thanks alot @SP, i can really work with this
On Sunday, February 10, 2019 at 7:41:33 PM UTC+2, sandeep patel wrote:
>
> Hello,@Mostwanted
> The code is working well. Actually in your view is not displaying anything
> at all because of initially items is none, so for loop will not iterate
> anything.
> For all this working well you have to insert a row in DB.
> I have updated the code so you don't need to do anything.
> Please test this code.
>
> #controller
>
> def countclick():
> items = db(db.countclick.created_by == auth.user.id).select()
> clicks = 0
> if len(items):
> for i in items:
> clicks = i.clicks
> return locals()
>
>
> def counter():
> item = db(db.countclick.created_by == request.vars.id).select()
> new_count = 1
> if len(item):
> for i in item:
> new_count = i.clicks + 1
> try:
> db.countclick.update_or_insert((db.countclick.created_by ==
> auth.user.id),clicks=new_count)
> except Exception as e:
> print(e)
> return "{}".format(new_count)
>
> #View
>
> {{extend 'layout.html'}}
>
> <input type="hidden" id="id" name="id" value="" />
>
>
> <a id="{{=auth.user.id}}"
> onclick="jQuery('#id').val('{{=auth.user.id}}');
> ajax('{{=URL('default', 'counter')}}', ['id'],
> 'item{{=auth.user.id}}');" href="#">clck</a>
> <p >
>
> Count=<span id="item{{=auth.user.id}}">{{=clicks}}</span>
> <span onclick="jQuery('#id').val('{{=auth.user.id}}');
> ajax('{{=URL('default', 'counter')}}', ['id'],
> 'item{{=auth.user.id}}');"></span>
> </p>
>
>
> Thanks
>
> SP
>
>
> On Sun, Feb 10, 2019 at 10:02 PM mostwanted <[email protected]
> <javascript:>> wrote:
>
>> Hey @SP, my view is not not displaying anything at all, my link is not
>> displayed!! I was working on your example above, I dont know if i am
>> missing something.
>>
>> On Sunday, February 10, 2019 at 3:24:38 PM UTC+2, sandeep patel wrote:
>>>
>>>
>>> @Mostwanted
>>> I think you can achieve this functionality by a couple of ways.
>>> One, you can store every clicks value in session but you can only store
>>> for the time being.
>>> Another way you can directly store every clicks values in DB.
>>> You can try this code
>>> #Model
>>>
>>> db.define_table('countclick',
>>> Field('clicks', 'integer', default=0),
>>> auth.signature
>>> )
>>>
>>> #Controller
>>>
>>> def countclick():
>>> items = db(db.countclick).select()
>>> return dict(items=items)
>>>
>>>
>>> def counter():
>>> item = db.countclick[request.vars.id]
>>> new_count = item.clicks + 1
>>> if item.update_record(clicks=new_count):
>>> print("Yes")
>>> else:
>>> print('N0')
>>> return "{}".format(new_count)
>>>
>>> #View
>>>
>>> {{extend 'layout.html'}}
>>>
>>> <input type="hidden" id="id" name="id" value="" />
>>>
>>> {{for item in items:}}
>>> <a id="{{=item.id}}"
>>> onclick="jQuery('#id').val('{{=item.id}}');
>>> ajax('{{=URL('default', 'counter')}}', ['id'], 'item{{=item.id}}');"
>>> href="#">Increment</a>
>>> <p >
>>>
>>> Count=<span id="item{{=item.id}}">{{=item.clicks}}</span>
>>> <span onclick="jQuery('#id').val('{{=item.id}}');
>>> ajax('{{=URL('default', 'counter')}}', ['id'],
>>> 'item{{=item.id}}');"></span>
>>> </p>
>>> {{pass}}
>>>
>>> For more information you can check here
>>> <http://web2py.com/books/default/chapter/29/11/jquery-and-ajax#Voting-and-rating>
>>>
>>> Thanks
>>>
>>> SP
>>>
>>>
>>> On Sun, Feb 10, 2019 at 5:38 PM mostwanted <[email protected]> wrote:
>>>
>>>> I am trying achieve something but i don't know how, i have a page
>>>> called Link (default/link.html) that has a link called Increment
>>>> {{=A('Increment', _id="increment",_href=URL('default', 'value'))}}
>>>>
>>>> and a page called value (default/value.html) that has a variable (X),
>>>> what i want is to have (X) incremented by 1 every-time I click the link
>>>> Increment in the page Link, this value should only increase by 1
>>>> every-time
>>>> a user clicks Increment, the value should not go back to zero or the
>>>> default value even when the user shuts own the system. I don't have a code
>>>> sample for this obviously coz i couldn't implement it, i only have this as
>>>> an idea, if anyone understands how i could implement this please help out.
>>>>
>>>> Regards;
>>>>
>>>> Mostwanted
>>>>
>>>> --
>>>> 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 [email protected].
>>>> 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 [email protected] <javascript:>.
>> 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 [email protected].
For more options, visit https://groups.google.com/d/optout.