-1
我正在開發一個php項目,客戶可以喜歡並且不像某個帖子。在MySQL數據庫喜歡clomn應增加或減少1即(+1或-1) 下面是我的SQL語法我不知道哪裏出錯請幫忙。sql語句不適合我
$time = date("Y-m-d H:i:s");
$sql_likes2 = "UPDATE `tble_likes` SET likes = `tble_likes`.`likes`-1 WHERE `tble_likes`.`postaID` = ? AND `tble_likes`.`useremail` = ?";
$SQL_statement_likes= $this->conn->prepare($sql_likes2);
$SQL_statement_likes->bindParam(1,$this->posta2);
$SQL_statement_likes->bindParam(2,$this->user_mail);
$SQL_statement_likes->execute();
if($SQL_statement_likes==true){
echo $this->user_mail;
$sql_countL = "SELECT COUNT(likes) AS SUM FROM tble_likes WHERE postaID=? GROUP BY postaID LIMIT 1";
$sql_statement_countL = $this->conn->prepare($sql_countL);
$sql_statement_countL->bindParam(1,$this->posta);
$sql_statement_countL->execute();
if($sql_statement_countL==true){
$row=$sql_statement_countL->fetch();
$unlike = $row[0];
echo $unlike;
}
}
列的數量不會增加或列的值減去後改變。取而代之的是使用簡單的select ... like查詢。 – Shadow
嘗試'SUM'而不是'COUNT'。 Count是單獨的行,sum是這些行的累積值。 – aynber
我甚至不清楚你是如何在首位存儲的。 – Shadow