php - 让页面在访问者刷新时更新字段

标签 php mysql

我的 mysql 查询有问题..

我的数据中有一个表..名称是(Info_website),字段是(NumVisitor)..

访问者刷新页面时的问题我想要归档 (NumVisitor + 1) 但实际上它 +2 ..

这是代码..

$sql2 = "UPDATE `Info_website` SET `NumVisitor` = `NumVisitor`+1 WHERE `Id`=1 LIMIT 1";
$query = mysqli_query($connect, $sql2) or die (mysqli_error());

非常感谢..

// New Comment

<?php
require("startsession.php");
require("config.php");
include "../include/header.php";
echo '<title>'.$setting['websit_title'].' - Main Page </title>';
?>
<br />
<br />
<table align="center" width="65%">
<tr>
    <td class="head_title" colspan="4">Information</td>
</tr>
<tr>
    <td width="35%">Number of New Book:</td>
    <td>
        <?php
            $sql = "SELECT IDkalemat FROM main_kalemat";
            $query = mysqli_query ($connect , $sql) or die (mysqli_error());
            $num = mysqli_num_rows($query);
            echo $num;
        ?>      
    </td>

    <td width="35%">Number of Users:</td>
    <td>
        <?php
            $sql = "SELECT IDUser FROM user_kalemat";
            $query = mysqli_query ($connect , $sql) or die (mysqli_error());
            $num = mysqli_num_rows($query);
            echo $num;
        ?>
    </td>
</tr>
        <tr>
        <td width="35%">Number Of Visitors:</td>
    <td>
        <?php
            $sql = "SELECT NumVisitor FROM Info_website";
            $query = mysqli_query ($connect , $sql) or die (mysqli_error());
            $num = mysqli_fetch_array($query);
            echo $num['NumVisitor'];
        ?>
    </td>
</tr>

</table>

<br />
<br />
<?php

//-------- from here the number of visitor

//--------- the end
$sql2 = "UPDATE Info_website SET NumVisitor = NumVisitor+1 WHERE Id=1 LIMIT 1"; 
$query = mysqli_query($connect, $sql2) or die (mysqli_error());
if ($query)
{
    echo '1';
}else{
    echo '0';
}
include ("../include/footer.php");
?>

最佳答案

听起来这段代码在每次页面访问时都会执行两次。您能向我们展示其余的代码吗?

关于php - 让页面在访问者刷新时更新字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3428137/

相关文章:

php - 为什么在 Laravel 5.2 的 blade.php 文件中没有显示这些数据

MySQL:主从查询中包含 WHERE 语句的不同结果?

mysql - 两个可能表的外键

sql - 将数据库从 MS SQL 迁移到 MySql - 耗时/困难程度如何?

mysql - mySQL 5.5 中范围的 SQL 错误

php - Node JS 到 PHP,无法正常工作

php - 使用 Temando API 创建预订

php - 查询 m-d-Y 时显示 SQL 结果中的年份

php - 嵌入式支付 IPN

mysql - 我可以在表达式映射文件中添加 SQL 查询吗?