<bdo id='nAKth'></bdo><ul id='nAKth'></ul>
        <tfoot id='nAKth'></tfoot>

        <small id='nAKth'></small><noframes id='nAKth'>

        <legend id='nAKth'><style id='nAKth'><dir id='nAKth'><q id='nAKth'></q></dir></style></legend>
        <i id='nAKth'><tr id='nAKth'><dt id='nAKth'><q id='nAKth'><span id='nAKth'><b id='nAKth'><form id='nAKth'><ins id='nAKth'></ins><ul id='nAKth'></ul><sub id='nAKth'></sub></form><legend id='nAKth'></legend><bdo id='nAKth'><pre id='nAKth'><center id='nAKth'></center></pre></bdo></b><th id='nAKth'></th></span></q></dt></tr></i><div id='nAKth'><tfoot id='nAKth'></tfoot><dl id='nAKth'><fieldset id='nAKth'></fieldset></dl></div>
      1. 使用复选框、PHP 和 MySQL 删除多行

        时间:2023-10-03
        <legend id='SUCpy'><style id='SUCpy'><dir id='SUCpy'><q id='SUCpy'></q></dir></style></legend>
          <bdo id='SUCpy'></bdo><ul id='SUCpy'></ul>
            <tbody id='SUCpy'></tbody>
        • <small id='SUCpy'></small><noframes id='SUCpy'>

            1. <tfoot id='SUCpy'></tfoot>

                  <i id='SUCpy'><tr id='SUCpy'><dt id='SUCpy'><q id='SUCpy'><span id='SUCpy'><b id='SUCpy'><form id='SUCpy'><ins id='SUCpy'></ins><ul id='SUCpy'></ul><sub id='SUCpy'></sub></form><legend id='SUCpy'></legend><bdo id='SUCpy'><pre id='SUCpy'><center id='SUCpy'></center></pre></bdo></b><th id='SUCpy'></th></span></q></dt></tr></i><div id='SUCpy'><tfoot id='SUCpy'></tfoot><dl id='SUCpy'><fieldset id='SUCpy'></fieldset></dl></div>
                  本文介绍了使用复选框、PHP 和 MySQL 删除多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  正如标题所示,我想从我的数据库中删除多行.为了实现这一点,我有两个文件,一个前端文件,它生成一个表格,显示用户可以删除的文件,这些文件使用复选框选择.

                  As the title suggests I want to delete multiple rows from my database. To accomplish this I have two files, a front end file that generates a table that shows the files a user may delete which are chosen using checkboxes.

                  后端文件是对选中的复选框进行处理,并使用SQL语句删除选中的文件.

                  The back end file is to process the selected checkboxes and use an SQL statement to delete the chosen files.

                  我遇到的问题是将选定文件的 id 从前端传递到后端.两个文件的代码如下:

                  The problem I am having is passing the id of a selected file from the front end to the back. The code for both files are below:

                  前端

                  //Build Table Query
                  $query="SELECT * FROM documents";
                  $result= mysqli_query($con, $query) or die("Invalid query");
                  
                  $count = mysqli_affected_rows($con); 
                  
                  ?>
                  <table width="400" border="0" cellspacing="1" cellpadding="0">
                  <tr>
                  <td><form name="form1" method="post" action="deletefilesback.php">
                  <table width="800" border="0" cellpadding="3" cellspacing="2" bgcolor="#CCCCCC">
                  <tr>
                  <td colspan="5" bgcolor="#FFFFFF" align="center"><strong>Delete Multiple         Files</strong></td>
                  </tr>
                  <tr>
                  <td align="center" bgcolor="#FFFFFF">#</td>
                  <td align="center" bgcolor="#FFFFFF"><strong>Id</strong></td>
                  <td align="center" bgcolor="#FFFFFF"><strong>Title</strong></td>
                  <td align="center" bgcolor="#FFFFFF"><strong>Description</strong></td>
                  <td align="center" bgcolor="#FFFFFF"><strong>File Location</strong></td>
                  </tr>
                  <?php
                  while($row = mysqli_fetch_array($result)){
                  ?>
                  <tr>
                  <td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox"  id="checkbox[]" value="<?php echo $rows['id']; ?>"></td>
                  <td bgcolor="#FFFFFF"><?php echo $row['id']; ?></td>
                  <td bgcolor="#FFFFFF"><?php echo $row['title']; ?></td>
                  <td bgcolor="#FFFFFF"><?php echo $row['description']; ?></td>
                  <td bgcolor="#FFFFFF"><?php echo $row['doc_link']; ?></td>
                  </tr>
                  <?php
                  }
                  ?>
                  <tr>
                  <td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit"   id="delete" value="Delete Files"></td>
                  </tr>
                  </table>
                  </form>
                  </td>
                  </tr>
                  </table>
                  

                  后端

                  $delete = $_POST['checkbox'];
                  
                  //Then do what you want with the selected items://
                  foreach ($delete as $id) {
                  
                  $query="DELETE FROM documents WHERE id = '".$id."'";
                  $result= mysqli_query($con, $query) or die("Invalid query");
                  
                  }
                  //Show that the items have been successfully removed.//
                  if (mysqli_affected_rows($con) > 0) {
                  echo '<p>The selected items have been successfully deleted.</p>';
                  } else {
                  echo '<p>An error has occurred while processing your request</p>';
                  }
                  ?>
                  

                  请注意,一旦这个工作正常,我将使用 unlink 函数使用前端表的 doc_link 部分删除服务器上的文件.谢谢

                  As a note, once this is working I will be using the unlink function to delete the file on the server using the doc_link part of the table on the front end. Thanks

                  推荐答案

                  在html页面中这样做

                  in html page do it like this

                  <input name="checkbox[<?php echo $row['id']?>]"
                  

                  在后端这样做

                  foreach ($delete as $id => $val) {
                      if($val=='checked'){
                          $query="DELETE FROM documents WHERE id = '".$id."'";
                          $result= mysqli_query($con, $query) or die("Invalid query");
                      }
                  }
                  

                  这篇关于使用复选框、PHP 和 MySQL 删除多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:根据另一个下拉列表填充下拉列表的最佳和最简 下一篇:PHP:使用 optgroup 动态下拉

                  相关文章

                  最新文章

                    <legend id='aC23E'><style id='aC23E'><dir id='aC23E'><q id='aC23E'></q></dir></style></legend>

                      • <bdo id='aC23E'></bdo><ul id='aC23E'></ul>

                      <small id='aC23E'></small><noframes id='aC23E'>

                    1. <i id='aC23E'><tr id='aC23E'><dt id='aC23E'><q id='aC23E'><span id='aC23E'><b id='aC23E'><form id='aC23E'><ins id='aC23E'></ins><ul id='aC23E'></ul><sub id='aC23E'></sub></form><legend id='aC23E'></legend><bdo id='aC23E'><pre id='aC23E'><center id='aC23E'></center></pre></bdo></b><th id='aC23E'></th></span></q></dt></tr></i><div id='aC23E'><tfoot id='aC23E'></tfoot><dl id='aC23E'><fieldset id='aC23E'></fieldset></dl></div>
                      <tfoot id='aC23E'></tfoot>