以下代码似乎不起作用,我不是MySQL的专家,但这似乎应该有用,任何线索?
if($params['action'] == 'createTab'){
$stmt = $dbh->prepare("
insert into
dashboard_data
(position, user_id)
values
(
(select
max(position) + 1
from
dashboard_data
where
user_id=:userid
),
:userid
)
");
$stmt->bindParam(':userid', $userId);
$stmt->execute();
答案 0 :(得分:1)
使用
insert into dashboard_data (position, user_id)
select max(position) + 1, :userid
from dashboard_data
where user_id = :userid