Update visits when opening the site

Asked

Viewed 45 times

1

I am doing a function to change the count of visits on my site. The function is this:

function visitas($conexao, $visita) {

    $query = "update visita set visitas= visitas + 1";

    return mysqli_query($conexao, $query);
}

But I don’t know how to make him count the visit automatically when viewing my site. Can anyone help me? Thanks in advance!

  • If I understood correctly, just call the function. Something like visitas($conexao, null) - the second parameter left null because he’s not even needed in the job.

  • Thank you very much Anderson

  • I didn’t understand why calling a function to count visit automatically at the time of viewing. It wouldn’t be enough just to run the query?

  • I am a layman....

  • 1

    quiet, we are here to help us

  • Thank you @Leocaracciolo

  • 1

    I don’t know if you’ve seen this post https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta/1079#1079

  • Opa.. vi no... I will take a look @Leocaracciolo, thank you very much!

Show 3 more comments

2 answers

1


function visitas($conexao, $visita = '') {

    $query = "update visita set visitas= visitas + 1";

    return mysqli_query($conexao, $query);
}

visitas($conexao);
  • The query is not about the query but rather about how and when to call the function.

  • sorry I arranged.

0

Without too many roundups and unnecessary turns, just run the query:

$query = "update visita set visitas= visitas + 1"; 
$data = mysqli_query($conexao, $query);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.