【发布时间】:2023-03-24 14:49:01
【问题描述】:
我想从 Mysql 数据库中的 stud_id 列中获取最大值并加 1
例如:如果我将 stud_id 设为 10 作为最大值,我应该将其加 1 并将结果 11 放回新的 stud_id 以用于下一条记录,但我得到一个错误为“数组到字符串转换”
stud_id
------
2
4
8
10
我的代码是
require 'Db.class.php';
$pdo=new DB();
$studid=$pdo->query("SELECT max(stud_id) maxcount FROM t_notes");
$version = $studid+1;
echo "$version";
【问题讨论】:
-
stud_id不是自动递增的有什么原因吗?另外,$studid不是你想的那样。 -
你为什么不直接使用
autoincreament?另外,你能 echo/print_r $stuid 并显示结果吗? -
@serakfalcon : 我在我的表中使用了两个主键,所以我不能自动增加字段 Stud_id