我有一个包含两列“Number”和“Date”的表格。我想检索最后一行的值但是这不起作用:
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT Number FROM functions_order_numbers ORDER BY Number DESC LIMIT 1";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
echo $row["Number"];
}
mysqli_close($conn);
我正在尝试创建增量唯一订单号
答案 0 :(得分:1)
如果您想在表格中使用增量编号,请使用auto_increment
:
create table t (
number int auto_increment primary key, -- usually it is a primary key
. . .
);
请勿尝试在应用层执行此操作。这很危险,因为同时进行多次更新可能无法做正确的事情。