Click counter

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
hhansen
Posts: 3
Joined: 2021-01-06 17:01

Click counter

Post by hhansen » 2021-01-07 11:05

I want to update a counter every time a user click on a record in table view.

I have created a field "vist" and added code in the hook-file:

function annoncer_dv($selectedID, $memberInfo, &$html, &$args){
if ($selectedID){
$id=makeSafe($selectedID);
$res=sql("UPDATE annoncer SET annoncer.vist=annoncer.vist+1 WHERE annoncer.id=$id", $eo);
}

}

It is however only the last entered record it works on... Any suggestions?

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1231
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Click counter

Post by onoehring » 2021-01-07 13:46

Hi,

would you tell us, from where (when) you call your function?
Your code looks fine to me but you should make sure that it's called every time - probably check if SelectedID is set in the _init function - and if it exists, call your function.

Olaf

hhansen
Posts: 3
Joined: 2021-01-06 17:01

Re: Click counter

Post by hhansen » 2021-01-07 16:29

Hi,

When I am in tableview and click on a record, and I have tried to add "sleep(5);" after the update call, where I can see it is called.

I want a counter showing how many times the record has been viewed, but maybe there is another way to do this?

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1709
Joined: 2018-04-01 10:12

Re: Click counter

Post by pbottcher » 2021-01-07 20:25

Hi,

I would guess that your vist field is not initialized, so the sql statement fails to increase the counter.

Try

Code: Select all

function annoncer_dv($selectedID, $memberInfo, &$html, &$args){
  if ($selectedID){
    $id=makeSafe($selectedID);
    $res=sql("UPDATE annoncer SET annoncer.vist=ifnull(annoncer.vist,0)+1 WHERE annoncer.id=$id", $eo);
  }

}
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

hhansen
Posts: 3
Joined: 2021-01-06 17:01

Re: Click counter

Post by hhansen » 2021-01-08 04:29

Hi,
I have just copied your changes, and it works perfect - thanks a lot !!

pasbonte
Veteran Member
Posts: 178
Joined: 2013-02-06 09:49

Re: Click counter

Post by pasbonte » 2022-02-01 07:16

Hello HHANSEN

I see that you have made a click counter, can you explain me more? I'm a beginner...

I see roughly but I don't know what to do: create a VIST field and where to place the code...

Post Reply