我有这个代码...
$q = "SELECT count FROM " . TABLE_PREFIX . "count WHERE 1 LIMIT 1;";
$r = mysql_query($q);
if (!$r) {
echo $q;
return false;
}
$o = mysql_fetch_object($r);
$count = $o->count + 1;
$q = "UPDATE " . TABLE_PREFIX . "count SET `count` = {$count}";
如您所见,它从数据库中选择字段(它只是一个数字)并在将其发送回数据库之前将其加 1...
是否可以跳过选择部分,而只是说类似的话:
`SET `count` += 1`
或者类似的东西?
最佳答案
试试这个。您可以更新列而无需获取和递增到该字段
UPDATE tablename set `count` = (`count`+1) WHERE 1 LIMIT 1;
关于PHP/MySQL : Is it possible to add one to the field without selecting from db?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32989185/