Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么mysql\u查询执行多次_Php_Mysql_Refresh - Fatal编程技术网

Php 为什么mysql\u查询执行多次

Php 为什么mysql\u查询执行多次,php,mysql,refresh,Php,Mysql,Refresh,我有一个函数和一个更新查询,如下所示: //Article Function function article() { if($_GET['action'] == "article" && !empty($_GET['id'])) { $id = intval($_GET['id']); $article = array(); $selectArticle = mysql_query("SELECT * FROM a

我有一个函数和一个更新查询,如下所示:

//Article Function
function article()
{
    if($_GET['action'] == "article" && !empty($_GET['id']))
    {
        $id = intval($_GET['id']);
        $article = array();
        $selectArticle = mysql_query("SELECT * FROM articles WHERE id='$id'");
        $rowArticle = mysql_fetch_array($selectArticle);

        $id = $rowArticle['id'];
        $title = stripcslashes($rowArticle['title']);
        $category = stripcslashes($rowArticle['category']);
        $image = stripcslashes($rowArticle['image']);
        $description = stripcslashes($rowArticle['description']);
        $full_description = stripcslashes($rowArticle['full_description']);
        $keywords = stripcslashes($rowArticle['keywords']);
        $url = "/article/" . $rowArticle['id'] . "/" . str_replace(" ","-",stripcslashes($rowArticle['title']));
        $article = array('id' => $id, 'title' => $title, 'category' => $category, 'image' => $image, 'description' => $description, 'full_description' => $full_description, 'keywords' => $keywords, 'url' => $url);
        mysql_query("UPDATE articles SET visits=visits+1 WHERE id='7'");
    }
    return $article;
}
该函数只调用了一次,但在刷新页面时查询会运行多次

   header("Location:your_page.php"); 
例如,在第一次加载中,访问列为24,刷新后,访问列为48


我不明白为什么我会被搞混了。

1.使用页眉并重定向页面

   header("Location:your_page.php"); 
2.您可以重定向到同一页或不同页

   Unset $_POST after inserting it to Database.
   unset($_POST);

您确定没有多次调用article函数吗?访问列是整数列吗?我只调用了一次这样的函数->$article=article();如何查看访问栏?代码每次都用
id=7
更新行,它不应该在
id=$id
的位置更新吗?您确定这不仅仅是将访问次数添加到自身吗?再次运行-是否
访问次数
现在96次?否每次我刷新页面24都会增加访问次数这与问题有什么关系?页面加载24次,但原因是什么?抱歉,我在错误的窗口中写了消息。您能告诉我们调用article()函数的代码吗?重写规则可能会影响这一点?