以下代码用于统计我网站中每个内容的点击次数,当我将db中的content_viewer列重置为0并运行网站测试代码结果不正确时出现的问题,它给出了第一个内容一段时间从1开始,有些时间从3开始,其余内容有时加1,有些时间加3。
$viewerQuery = "UPDATE contents SET content_viewer = content_viewer + 1
WHERE content_id = $id " ;
$executeQuery = mysqli_query($conn,$viewerQuery);
$query = "SELECT * FROM contents WHERE content_id='$id'";
$result = mysqli_query($conn,$query);
while ($row = mysqli_fetch_array($result)){
$name = $row['content_name'];
$url = $row['url'];
$summary = $row['content_summary'];
$type = $row['content_type'];
$rate = $row['avg_rate'];
echo $row['content_viewer'];
}