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?
Click counter
Re: Click counter
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
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
Some postings I was involved, you might find useful:
Multi Path Upload (MPU) / dynamic upload folder; SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button
Multi Path Upload (MPU) / dynamic upload folder; SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button
Re: Click counter
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?
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?
Re: Click counter
Hi,
I would guess that your vist field is not initialized, so the sql statement fails to increase the counter.
Try
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.
Re: Click counter
Hi,
I have just copied your changes, and it works perfect - thanks a lot !!
I have just copied your changes, and it works perfect - thanks a lot !!
Re: Click counter
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...
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...