它很容易讓我們說你正在使用的mysqli:
$query= "SELECT * FROM TableA limit 3";
//takes first 3 rows from TableA
//$con being the connection string in config file
$result = mysqli_query($con,$query);
while($row = mysqli_fetch_array($result)){
//takes each row by row
$username = $row['username'];
$password = $row['password'];
//now that we initiated variables the sql query
$query1 = "INSERT INTO TableB (username, password) VALUES ('$username', '$password');
mysqli_query($con,$query1);
}
希望這有助於
編輯: 我剛纔讀,它應該有一個數組,所以你應該查詢改成這樣:
for($i=0; $i<count(array), $i++){
$query= "SELECT * FROM TableA WHERE ID = '$array[i]'";
//$con being the connection string in config file
$result = mysqli_query($con,$query);
while($row = mysqli_fetch_array($result){
//takes each row by row
$username = $row['username'];
$password = $row['password'];
//now that we initiated variables the sql query
$query1 = "INSERT INTO TableB (username, password) VALUES ('$username', '$password');
mysqli_query($con,$query1);
}
}
請採取[旅遊](http://stackoverflow.com/tour)。 –
你的id不能同時有多個值*,試試'WHERE \'id \'IN(1,3,5)'(顯然是在這裏使用你的數組) – ccKep