我希望添加一个函数,该函数将从表中的特定列获取最大数量,并在执行INSERT查询之前添加到该函数中。 (我不能让它自动增加,因为几个条目需要具有相同的值,这是通过if语句控制的)但是它不是这样做的,并且不会根据最高值将它增加1。
$max = "SELECT MAX(LocationID) FROM boss";
$result = mysqli_query($connection, $max);
$locID = $result+1;
$query = "INSERT INTO boss (ID, Name, Type, Location, LocationID, Difficulty) VALUES ('0', '$boss', '$type', '$loc', '$locID', '$diff')";
答案 0 :(得分:1)
您无需为此使用两个查询,您可以在INSERT
查询中执行此操作。
$query = "INSERT INTO boss (ID, Name, Type, Location, LocationID, Difficulty)
SELECT '0', '$boss', '$type', '$loc', MAX(locationID)+1, '$diff'
FROM boss";
答案 1 :(得分:0)
您忘记了获取结果
$max = "SELECT MAX(LocationID) as m FROM boss";
$result = mysqli_query($connection, $max);
$result = mysqli_fetch_array($result);
$locID = $result[0]+1;