0

我有一个组,组长正在更新组中的成员。角色 ID 为 11 的成员处于待处理状态,我想根据下拉列表中选择的选项更改他们的角色 ID。

这是表格:

<form action='updatePendingMembers.php' method='post' onsubmit='return checkForm()'>
    <?php
    $pendingMembers = "SELECT m.id, concat(fname, ' ', lname) as mName, email, m.rolesID FROM member m join member_to_groups on m.id = member_to_groups.memberID left join groups on member_to_groups.groupsID = groups.id WHERE m.rolesID = 11 AND groups.memberID = " . $_SESSION['siteMemberId'];
    $rsPendingMembers = mysql_query($pendingMembers);
    //if(!$rsPendingMembers)
        //echo 'the query is: ' . $pendingMembers . '<br/>and the error: ' . mysql_error();
    while($get_row = mysql_fetch_assoc($rsPendingMembers)){
    ?>
    <tr>
      <td colspan="3" class="Sub_Header">Pending Group members</td>
    </tr>
    <tr>
      <td colspan="3"><span class="Maintext"><?php echo $get_row['mName']?></span>
    <select name="rolesID" class="lowermenu" id="rolesID">
        <option value="12">Accept</option>
        <option value="11">Decline</option>
    </select>
      <a href="mailto:<?php echo $get_row['email']?>"><span class="lowermenu">send pending member message</span></a></td>
        </tr>
    <?php } ?>
    <td><span class="Sub_Header">
        <input name="update_pending_member_button" type="submit" id="update_pending_member_button" value="Update Member">
      </span></td>
      </form>

这是到目前为止的 updatePendingMembers.php 文件:

<?php
session_start();
include("global.php");
$myQuery1 = "UPDATE member SET rolesID = " .  mysql_real_escape_string($_POST['rolesID']) WHERE id = ;
$rs1 = mysql_query($myQuery1);
?>

如何将 id 设置为与被选中的成员以及该特定组中的成员相等?谢谢。

4

1 回答 1

1

对表单元素使用类似数组的名称:

<select name="rolesID[<?php echo $get_row['id']; ?>]" class="lowermenu" id="rolesID">
    <option value="12">Accept</option>
    <option value="11">Decline</option>
</select>

您的$_POST数据将如下所示:

$_POST['rolesID'] = array(
   '1' => '11',
   '2' => '12'
);

您可以遍历它并更新每条记录:

foreach ($_POST['rolesID'] as $id => $role) {
    $id = (int)$id;
    $role = (int)$role;
    $sql = "UPDATE member SET roleID = {$role} WHERE id = {$id}";
}
于 2013-01-10T21:23:58.803 回答