-1

这是将一些数据从一个表移动到另一个表的答案,它可能不是最好的,但它确实有效。

$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";

无论如何感谢您的帮助....哦,我修复了它,以便“'”不会出错。

4

1 回答 1

2

试试这个查询。

$result = mysqli_query($con, "INSERT INTO Teachers (First, Last, Depart) SELECT First, Last, Depart FROM Teacher_staff");

这就是你应该运行的所有内容。

如果您可以访问 PHP 之外的数据库(phpMyAdmin 或命令行),我建议您从那里运行该查询。

于 2013-11-14T23:19:39.773 回答