I want to build a feature that enables the user to moderate questions and is similar to wordpress comment or typical email moderation that uses a checkbox to approve/delete many questions at once.
How would I modify the following code to check which the questions are checked and react to the delete buttons when pressed? You may notice from the below code that I can currently do this with individual questions but I want to give the user more power.
<h2><a href="#">Moderate Questions</a></h2>
<div>
<button type="button" class="btn" name="delete" id="delete">Delete</button>
<button type="button" class="btn" name="approve" id="approve">Approve</button>
<?php
// Select all unapproved questions in db
$sql = "SELECT question_id, question, DATE_FORMAT(question_date, '%e %b %Y at %H:%i') AS dateattime FROM questions WHERE question_approved='0' ORDER BY question_date DESC";
$result = mysql_query($sql);
$myquestions = mysql_fetch_array($result);
if($myquestions) {
do {
$question_id = $myquestions["question_id"];
$question = $myquestions["question"];
$dateattime = $myquestions["dateattime"];
echo "<div class='question'>";
echo "<span value='$question_id'>";
echo "<input name='checkbox' type='checkbox' id='checkbox' value='$question_id'>";
echo "$question - <span class='date'>Asked $dateattime </span>";
echo "</span>\n";
echo "<div class='question-controls'><a href='".$_SERVER["PHP_SELF"]."?delete=$question_id' title='Delete this question' class='delete' onclick='return confirm(\"Are you sure you want to delete this question?\")'>Delete</a> | <a href='#'>Edit</a> |";
echo " <a href='".$_SERVER["PHP_SELF"]."?approve=$question_id' title='Publish this question'>Approve</a></div>";
echo "</div>";
} while ($myquestions = mysql_fetch_array($result));
} else {
echo "<p>No one has asked a question recently.</p>";
}
?>
</div>