为什么mysql_query执行多次

时间:2013-06-19 20:36:22

标签: 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 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;
}

该函数只调用一次,但是当我刷新页面时,查询会多次运行。

例如,在第一次加载时,访问次数列为24,刷新后访问次数列为48 !!!!!!

我无法理解为什么我会混淆

1 个答案:

答案 0 :(得分:-1)

1 ..使用标题并重定向页面。

   header("Location:your_page.php"); 

2 ..您可以重定向到同一页面或不同页面。

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