-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 に答える