Count and show it on screen, but when reloading do not restart the count, either with JavaScript or Php

1

Hello friends, I would like to know how to make you tell me the number of click that you make to a part of a page, and show it, I would like to do it with php so that those clicks are saved in the database but it is easier with javascript but when reloading I reboot the count ..

Greetings and thank you in advance

    
asked by DanielDaniel 06.08.2018 в 19:38
source

2 answers

2

The most advisable thing is that you learn jquery whether you do not understand it or if it is basically something that is really necessary or almost obligatory, so to speak and the syntax is very easy. Look at this example.

$(document).click(

    //hacemos una llamada ajax a un archivo php que guardara el click ejemplo
       $.ajax({

        url:"guardar_click.php",
        success:function(data){
           alert(data)
        }
       })

    });

save_click.php

<?php

//por ejemplo esta sentecia sql actualisaria cada click que des 
$sql=mysqli_query($conn,"UPDATE guardar_click SET click=click+1");

 $row=mysqli_fecht_array($sql);

 echo $row["click"];//retornamos el numero de veces que se ha clikeado

?>
    
answered by 06.08.2018 / 20:08
source
0

if you use jQuery you can try the following

$(document).click(
   $.post("guardarClick.php")
);

and in PHP you would only save +1 to a counter in some database

    
answered by 06.08.2018 в 19:45