我有這個職位表設置,其中有一個hits
列。 hits
列用於存儲查看帖子的次數。但是,問題出在更新查詢中。數據庫位於本地(開發)機器上,因此我是唯一訪問該腳本的用戶。當我查看一篇文章,它會更新,但與假數據一樣,如果當前計數有10,當我查看它跳轉到25左右的頁面....非常隨機......但增量。我想知道我哪裏出錯了。這裏是一個代碼示例:瀏覽量的計數器更新與虛假數據
Public function getPost()
{
//some data query to get post data and the post id
$this->viewsCounter($pid);
Return post data as array.
}
第一種方法是好的,現在這裏是viewsCounter()
方法
Public function viewsCounter($pid)
{
$this->query("update post set hits=hits+1 where id='$pid' ");
}
我hits
列設置了這樣hits int(255) NOT NULL
請幫助什麼是缺少在這裏?
也許你在單個請求期間多次調用'viewsCounter()'方法? –
'$ this-query'?是不是'$ this-> query'? – Faridzs
hits int(255)NOT NULL錯誤使它成爲int(11)和無符號的 – Sundar