0

我想构建一个功能,使用户能够审核问题,类似于 wordpress 评论或使用复选框一次批准/删除许多问题的典型电子邮件审核。

我将如何修改以下代码以检查检查了哪些问题并在按下时对删除按钮做出反应?您可能会从下面的代码中注意到,我目前可以处理个别问题,但我想给用户更多的权力。

 <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>
4

1 回答 1

1

您需要修改“复选框”元素以创建一个值数组。代码:

echo "<input name='checkbox[]' type='checkbox' id='checkbox' value='$question_id'>";

之后,您可以从 php 代码中调用此变量(例如使用 $_REQUEST['checkbox']),它将是数组。所以你可以遍历它并从数据库中删除这些行。

于 2009-12-18T13:11:31.770 回答