以下是将一些数据从一个表移动到另一个表的答案,它可能不是最好的,但确实有效。
$result = mysqli_query($con,"SELECT * FROM Teacher_staff");
while($row = mysqli_fetch_array($result))
{
// you don't need this step but it checks the select data portion
echo $row['First'] . " " . $row['Last'] . " " . $row['Id'];
// assign your variables, might not need this step as well
$First = $row['First'];
$Last = $row['Last'];
$id = $row['Id'];
// takes the information from the first mysqli and inserts it into the second table.
$sql="INSERT INTO teachers (First, Last, Id)
VALUES
(
'".addslashes($First)."',
'".addslashes($Last)."',
'".addslashes($Depart)."',
'".addslashes($id)."'
)";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
// confirms that each record is added to the table.
echo "1 record added";
}
echo "<br>";
mysqli_close($con);
echo "done";
任何方式都要感谢帮助....哦,我修复它,以便“'”不会出错。
答案 0 :(得分:2)
尝试此查询。
$result = mysqli_query($con, "INSERT INTO Teachers (First, Last, Depart) SELECT First, Last, Depart FROM Teacher_staff");
这就是你应该运行的全部内容。
如果您可以访问PHP之外的数据库(phpMyAdmin或命令行),我建议您从那里运行该查询。