2015-02-23 81 views
0

我正在创建一个我希望能够批准,拒绝或删除的用户列表。我不想一个接一个地做,因为这样做太多了。 My list of users试图批准,拒绝或删除多个用户

我有以下的批准,拒绝和删除列代码:

<tr> 
 
    <input type="hidden" name="user_id" value="'.$row['user_id'].'"> 
 
    <td style="text-align:center; padding:20px; background-color:#DFF0D8;"> 
 
     <input type="radio" name="approve[]" value="1"> 
 
    </td> 
 
    <td style="text-align:center; padding:20px; background-color:#FCF8E3;"> 
 
     <input type="radio" name="approve[]" value="0"> 
 
    </td> 
 
    <td style="text-align:center; padding:20px; background-color:#FCDEDE;"> 
 
     <input type="radio" name="approve[]" value="3"> 
 
    </td> 
 
</tr>

我希望能够设置“批准”在表列“用户“在MySQL中为1,如果它被批准,并且在被拒绝的情况下保持为0。如果选择“删除”,那么我希望能够删除该行数据。我怎样才能做到这一点的用户名单?如果只是一个接一个,那很容易,但我不知道如何为多个用户做到这一点。

我想通过“批准”数组循环,但我无法更改数据库中的值,因为我不知道如何将其与user_id匹配。

任何帮助表示赞赏。

+0

我看到这里有两个可能的路径:要么有一个新的集为每个用户提供一个新的'name',或者认为这是三个多选择'select',批准,拒绝,删除和委托,为客户端JS提供更好的前端显示。 – 2015-02-23 18:41:18

+0

谢谢@UlrichSchwarz Schwwarz!我是这个东西的新手......如果我要求你更详细地解释一下这个问题,会不会太麻烦?我只是不确定如何去做这些选择。 – Rookie 2015-02-25 17:24:25

回答

0

这里是多删除样本:

的index.php

<?php include('dbcon.php'); ?> 
<form method="post" action="delete.php" > 
<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example"> 
         <div class="alert alert-info"> 

          <strong>Check the radion Button and click the Delete button to Delete Data</strong> 
         </div><thead> 

          <tr> 
           <th></th> 
           <th>FirstName</th> 
           <th>LastName</th> 
           <th>MiddleName</th> 
           <th>Address</th> 
           <th>Email</th> 
          </tr> 
         </thead> 
         <tbody> 
         <?php 
         $query=mysql_query("select * from member")or die(mysql_error()); 
         while($row=mysql_fetch_array($query)){ 
         $id=$row['member_id']; 
         ?> 

            <tr> 
            <td> 
            <input name="selector[]" type="checkbox" value="<?php echo $id; ?>"> 
            </td> 
            <td><?php echo $row['firstname'] ?></td> 
            <td><?php echo $row['lastname'] ?></td> 
            <td><?php echo $row['middlename'] ?></td> 
            <td><?php echo $row['address'] ?></td> 
            <td><?php echo $row['email'] ?></td> 
          </tr> 

           <?php } ?> 
         </tbody> 
        </table> 
        <input type="submit" class="btn btn-danger" value="Delete" name="delete"> 

delete.php

<?php 
include('dbcon.php'); 
if (isset($_POST['delete'])){ 
$id=$_POST['selector']; 
$N = count($id); 
for($i=0; $i < $N; $i++){ 
$result = mysql_query("DELETE FROM member where member_id='$id[$i]'");} 
header("location: index.php"); } ?> 
+0

请不要暗示不推荐使用的库(在本例中为**'mysql_ *'**),因为它们不安全/过时。 – Darren 2015-02-24 01:41:36

0

对于多个用户,你只需要添加一个维度到所有表单变量名称:

<tr> 
    <td style="text-align:center; padding:20px; background-color:#DFF0D8;"> 
     <input type="radio" name="approve[<?= $row['user_id'] ?>]" value="1"> 
    </td> 
    <td style="text-align:center; padding:20px; background-color:#FCF8E3;"> 
     <input type="radio" name="approve[<?= $row['user_id'] ?>]" value="0"> 
    </td> 
    <td style="text-align:center; padding:20px; background-color:#FCDEDE;"> 
     <input type="radio" name="approve[<?= $row['user_id'] ?>]" value="3"> 
    </td> 
</tr> 

当表单发送您会收到这样的事情:

approve[123]=1&approve[456]=2&... 

这将打开$_POST['approve']到一个数组:

array(
    123 => 1 
    456 => 2 
); 
... 
+0

谢谢@Ja͢ck为您解答。什么是123?并将1选项(批准,否认,删除)? – Rookie 2015-02-25 16:39:44