Php 插入一个新行,从同一个表中获取一些值
需要在galls表中插入新行 cnt字段应从同一个表中复制-从特定的行id复制 ind字段应作为给定变量-$ind 这是我的尝试获取语法错误Php 插入一个新行,从同一个表中获取一些值,php,mysql,Php,Mysql,需要在galls表中插入新行 cnt字段应从同一个表中复制-从特定的行id复制 ind字段应作为给定变量-$ind 这是我的尝试获取语法错误 $id = 3; $ind = 5; $sq = "insert into galls(cnt, ind) values (select (cnt) from galls where id = :aid, :aind)"; $st = $db->prepare($sq); $st->execute([ ":
$id = 3;
$ind = 5;
$sq = "insert into galls(cnt, ind) values (select (cnt) from galls where id = :aid, :aind)";
$st = $db->prepare($sq);
$st->execute([
":aid" => $id,
":aind" => $ind
]);
在子查询中使用静态值
$sq = "insert into galls(cnt, ind) values (select cnt, :aind from galls where id = :aid)";
我认为你有一个很大的语法问题; 试试这个: 插入gallscnt,ind values从galls中选择cnt,其中id=:aid,:aind
顺便说一句,这对我来说有点奇怪。表中的列是什么?子查询select语句应完全位于括号内,作为values语句的第一对参数。值子查询,b,c@Scuzzy-我尝试了-值从galls中选择cnt,其中id=:aid,:aind;-语法错误againtried allready-参见我对Scuzzy的回答comment@qadenza你为什么不试着分开做呢?首先选择cnt,然后将其插入表中。它更容易调试。