Note that there are some explanatory texts on larger screens.

plurals
  1. PODelete multiple rows if checkbox is checked
    text
    copied!<p>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.</p> <p>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.</p> <pre><code> &lt;h2&gt;&lt;a href="#"&gt;Moderate Questions&lt;/a&gt;&lt;/h2&gt; &lt;div&gt; &lt;button type="button" class="btn" name="delete" id="delete"&gt;Delete&lt;/button&gt; &lt;button type="button" class="btn" name="approve" id="approve"&gt;Approve&lt;/button&gt; &lt;?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 "&lt;div class='question'&gt;"; echo "&lt;span value='$question_id'&gt;"; echo "&lt;input name='checkbox' type='checkbox' id='checkbox' value='$question_id'&gt;"; echo "$question - &lt;span class='date'&gt;Asked $dateattime &lt;/span&gt;"; echo "&lt;/span&gt;\n"; echo "&lt;div class='question-controls'&gt;&lt;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?\")'&gt;Delete&lt;/a&gt; | &lt;a href='#'&gt;Edit&lt;/a&gt; |"; echo " &lt;a href='".$_SERVER["PHP_SELF"]."?approve=$question_id' title='Publish this question'&gt;Approve&lt;/a&gt;&lt;/div&gt;"; echo "&lt;/div&gt;"; } while ($myquestions = mysql_fetch_array($result)); } else { echo "&lt;p&gt;No one has asked a question recently.&lt;/p&gt;"; } ?&gt; &lt;/div&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload