我有一個函數,並在其中一個更新查詢是這樣的:爲什麼的mysql_query執行多次
//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 !!!!!!
我無法理解爲什麼我混了
確定文章函數不會被多次調用嗎?並且訪問列是一個整數列嗎? – Havsmonstret
我只需要調用一次函數 - > $ article = article(); –
你如何查看訪問列?代碼每次都更新一行'id = 7',不應該更新'id = $ id'的位置嗎? – Havsmonstret