【发布时间】:2012-07-16 09:47:40
【问题描述】:
我有一个从以下 PDO 获得的数组:
$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 值,我需要运行一个插入查询,该查询获取 dID 并将其插入到具有外部值的同一数据库中的表中。
$sqlIns = "INSERT INTO messages (dID, message, status") VALUES (?,?,?);
消息和状态将保存在一个变量中
谁能帮我解决这个问题?
【问题讨论】:
-
为什么不在一个查询中完成所有这些操作?