我有一個名爲submission
的MySQL數據庫表,其中有一個名爲points
的字段,其類型爲bigint(100)
。將變量的值添加到數據庫字段
在一個PHP文件中,我有一個變量,其數值爲$commentpoints
。
在PHP文件中,我怎樣才能將$commentpoints
添加到points
?
我有一個名爲submission
的MySQL數據庫表,其中有一個名爲points
的字段,其類型爲bigint(100)
。將變量的值添加到數據庫字段
在一個PHP文件中,我有一個變量,其數值爲$commentpoints
。
在PHP文件中,我怎樣才能將$commentpoints
添加到points
?
它在你的SQL更新查詢其添加的問題:
$sql = 'UPDATE submissions
SET points = points + ' . (int) $commentpoints . '
WHERE id = ' . (int) $id;
這將增加$commentpoints
在數據庫中的點值;只要確保使用where子句,以便不將其添加到提交表中的每個記錄。
UPDATE table SET points = '[your value]'
mysql_query("UPDATE submission SET points = '$commentpoints'");
$sql = "UPDATE submission
SET points = points + ?
WHERE commentid=?";
$q = $conn->prepare($sql);
$q->execute(array($commentpoints,$commentid));