这是我的PHP代码段:
$con = mysqli_connect('localhost','root','','db');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"db");
$sql = "UPDATE nations SET queue='MAX(queue) FROM nations' WHERE nation_name='$nation'";
$query = mysqli_query($con,$sql);
$result = mysqli_fetch_assoc($query);
根据我的理解,查询应从列queue
获取当前最高值,然后将1添加到该结果,并将 新值插入表中。这不是我想要的方式,它只是将队列设置为0 ...
答案 0 :(得分:3)
使用
UPDATE nations
SET queue = (SELECT MAX(queue)+1 FROM nations)
WHERE nation_name = '$nation'