我有一个从以下 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 (?,?,?);
消息和状态将保存在一个变量中
任何人都可以帮我解决这个问题吗?