<?php
// Replace these variables with your Q2A database credentials
$databaseHost = 'your_database_host';
$databaseUser = 'your_database_username';
$databasePassword = 'your_database_password';
$databaseName = 'your_database_name';
// Establish a connection to the Q2A database
$connection = mysqli_connect($databaseHost, $databaseUser, $databasePassword, $databaseName);
if (!$connection) {
die("Connection failed: " . mysqli_connect_error());
}
// Get unanswered question IDs
$query = "
SELECT q.postid
FROM qa_posts q
LEFT OUTER JOIN qa_posts a ON a.parentid = q.postid
WHERE q.type = 'Q' AND a.parentid IS NULL;
";
$result = mysqli_query($connection, $query);
// Delete unanswered questions and their associated answers
while ($row = mysqli_fetch_assoc($result)) {
$postID = $row['postid'];
try {
// Delete associated answers (child posts) first
mysqli_query($connection, "DELETE FROM qa_posts WHERE parentid = $postID AND type = 'A';");
// Delete unanswered question (parent post)
mysqli_query($connection, "DELETE FROM qa_posts WHERE postid = $postID;");
} catch (Exception $e) {
// Handle any exceptions that may occur during the deletion process
echo $e->getMessage() . "\n";
}
}
// Close the database connection
mysqli_close($connection);
?>