是否可以从表中提取最高ID(在本例中为9)并将其作为变量$ maximum返回,以后可以用作整数?
答案 0 :(得分:1)
您可以使用MAX()
功能。可以找到文档here
答案 1 :(得分:0)
您可以尝试以下代码段:
$sql = "SELECT * FROM some_table where id = (select max(id) from some_table)";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "id = " . $row["id"];
}
}
答案 2 :(得分:0)
尝试一下,它将必须工作。
$sql = "SELECT id FROM some_table ORDER BY id DESC LIMIT 1";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "id = " . $row["id"];
}
}
答案 3 :(得分:0)
尝试一下,它将必须工作。
$sql = "SELECT id FROM some_table ORDER BY id DESC LIMIT 1";
$result = $conn->query($sql);
$id = 0;
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$id = $row["id"];
}
}
echo $id;