通过复选框更新php和mysql中的多行


Update multiple rows in php and mysql by checkbox

在html中的GUI上,有以下代码用于显示数据表

                <table  class="display table table-bordered table-striped" id="dynamic-table"  >
                    <thead>
                        <tr>
                            <th></th>
                            <th>CURRENT USER</th>
                            <th>ID</th>
                            <th>ID FACTORY</th>
                            <th>CATEGORY</th>
                            <th>MODEL</th>
                             <th>DB</th>
                            <th>DESCRIPTION</th>
                            <th>STATUS</th>                     
                        </tr>
                    </thead>
                     <!--PHP module-->
                    <?php require '../../modules/associativedevicesbackend.php';?>
                     <!--PHP module-->
             </table>
           </form>
         </div>   

在后面的表格里,我填上了这个:

 while($row=mysql_fetch_array($searchnodes))
 {
  echo "<tr>";
  echo "<td><input type='"checkbox'" name='"checkbox[]'" value='"'" id='"checkbox'"></td>";
  echo"<td> $row[USER_NAME] </td>";
  echo"<td align='right'> $row[DEVICE_ID] </td>";
  echo "<td> $row[DEVICE_FACTORY_ID] </td>";
  echo "<td> $row[CATEGORY_NAME] </td>";
   echo "<td> $row[DEVICE_MODEL] </td>";
 echo "<td> $row[DEVICE_BELONGING] </td>";
 echo "<td> $row[DEVICE_DESCRIPTION] </td>";
  echo"<td> $row[DEVICE_STATUS] </td>";
  echo "</tr>";
 }    cxz

我如何将文本框的数据发送到另一个填充以处理UPDATE

如果您想区分在表单中发送时标记了哪些复选框,您有两个选项:

  1. 为每个复选框指定一个唯一的名称,以便您知道选中了哪个复选框:
    ... name='"checkbox[{$row[DEVICE_ID]}]'" ...

  2. 为每个复选框指定一个唯一值(原因相同…):
    .. value='"{$row[DEVICE_ID]}'" ...

当然,假设{$row[DEVICE_ID]}唯一地标识您的行。

现在,您可以在php中的复选框数组上循环,根据键或值,您将确切地知道选中了哪一个。

请注意,只有选中的复选框才会在您发送表单时发送到服务器。