我有我從下面的PDO得到一個數組:PDO陣列從MySQL查詢到插入查詢
$sqlQry = "SELECT Devices.dID FROM Friends LEFT OUTER JOIN Devices ON Friends.fID = Devices.dUID WHERE Devices.dID IS NOT NULL GROUP BY Devices.dID";
$db = getConnection();
$sth = $db->prepare($sqlQry);
$sth->execute();
print("Fetch all of the remaining rows in the result set:\n");
$result = $sth->fetchAll();
print_r($result);
數組返回:
Array ([0] => Array ([dID] => 2[0] => 2) [1] => Array ([dID] => 3 [0] => 3))
對於DID值中的每一個I需要運行插入查詢,該插入查詢採用dID並將其插入到具有外部值的同一個數據庫中的表中。
$sqlIns = "INSERT INTO messages (dID, message, status") VALUES (?,?,?);
消息和狀態將在可變
舉行任何一個可以幫助我這一個?
爲什麼不在一個查詢中完成這一切? – RedFilter 2012-07-17 13:04:18