我想从一个表 ( oldDataTable) 中选择一些列并插入到另一个表 ( newDataTable) 中。两者都在同一个数据库中。我试过了。如果我只选择一列它的工作原理。但如果我选择不止一列,则不会发生任何事情。oldDataTable 有像这样的列Name | Date | Voltage | Current | Power | RMS.我只想选择像这样的列Name| Date| Power并将其插入到newDataTable. 当用户提交表单按钮时,我正在这样做。请任何帮助。<?phpif (isset($_POST['submit'])){ include ("DBconnect.php"); $conn= mysqli_connect( $dbhost, $dbuser, $dbpass, $db ); if ($conn->connect_error){ die("Connection failed: " . $conn->connect_error); } else{ $insertNEQuery= "INSERT INTO newDataTable (Name, Date, Power) SELECT (Name, Date, Power) FROM oldDataTable WHERE ID = '2' "; //it should be a bunch of rows. I have data for every one minute. mysqli_query($conn, $insertNEQuery); echo " data updated!"; $conn->close(); }} else echo " please click submit button!";?>```
2 回答
慕姐4208626
TA贡献1852条经验 获得超7个赞
中不需要括号SELECT
,以下查询将起作用。
INSERT INTO newDataTable (Name, Date, Power) SELECT Name, Date, Power FROM oldDataTable WHERE ID = '2'
所以你的代码将是:
$insertNEQuery= "INSERT INTO newDataTable (Name, Date, Power) SELECT Name, Date, Power FROM oldDataTable WHERE ID = '2' ";
大话西游666
TA贡献1817条经验 获得超14个赞
使用此查询
INSERT INTO newDataTable (SELECT Name, Date, Power FROM oldDataTable WHERE ID = '2')";
- 2 回答
- 0 关注
- 247 浏览
添加回答
举报
0/150
提交
取消