I would like to remove all rows from three different tables that matches a specific ID.
All three tables uses the same ID: chat_id
.
How do I delete all rows from three different tables WHERE chat_id
= 1234
?
Example:
$stmt = $mysqli->prepare('DELETE FROM table1, table2, table3 WHERE chat_id = ?');
I should mention that this is inside a loop see below.
My full code:
$stmt = $mysqli->prepare('SELECT chat_id FROM chat_id WHERE chat_expire < NOW()');
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
$chatid[] = $row['chat_id'];
}
$stmt->close();
foreach($chatid as $id) { // Delete all old posts.
$stmt = $mysqli->prepare('DELETE FROM chat_id, chat_msg, chat_nick WHERE chat_id = ?');
$stmt->bind_param('s', $id);
$stmt->execute();
$stmt->close();
}