How to count thousands of daily visits

85 views Asked by At

I have a classifieds site with thousands of daily visits. I would like some advice: how can I count the visits of each ad and show the final data to the user who entered the ad?

Now I'm saving the visits to the database, but when I add them it takes a long time.

Can you recommend a quicker solution to save the total visits of each individual ad?

My code that updates visits:

$nomehost = "";
$nomeuser = "";
$password = "";
$nomedb = "";
$connect = new MySQLi($nomehost,$nomeuser,$password,$nomedb);

$sql="SELECT * FROM immobili_d";
$result=mysqli_query($connect,$sql);

while ($row=mysqli_fetch_array($result)) {
    $sqlvisite="SELECT COUNT(id) FROM pageview WHERE idAnnuncio ='".$row['id']."'";
    $resultvisite=mysqli_query($connect,$sqlvisite);
    $visite = mysqli_fetch_array($resultvisite);
    
    $queryUpdate = $connect->prepare("UPDATE immobili SET visite_tot=? WHERE id = ? ");
  $queryUpdate->bind_param('ii', $visite['COUNT(id)'], $row['id']);
  $resultUpdate = $queryUpdate->execute();

  $sqlcontatti="SELECT COUNT(id) FROM sendrequest WHERE immobile_id ='".$row['id']."'";
  $resultcontatti=mysqli_query($connect,$sqlcontatti);
  $contatti = mysqli_fetch_array($resultcontatti);
  
  $queryConUpdate = $connect->prepare("UPDATE immobili SET contatti_tot=? WHERE id = ? ");
$queryConUpdate->bind_param('ii', $contatti['COUNT(id)'], $row['id']);
$resultConUpdate = $queryConUpdate->execute();
}

0

There are 0 answers