1
我正在處理一個項目,我想通過使用複選框中的值更新表來爲用戶分配一個角色。我想用複選框更新多個記錄。我想從下拉菜單中選擇用戶時更新新的服務表。在這個階段我需要幫助。當我使用php pdo檢查複選框時,如何更新多個記錄?
#assign estimator
$gp = $userDetails->pgroup;
$users = $db->prepare('SELECT
dbo.[GWCL$west_users].name AS fullname,
dbo.[GWCL$west_users].user_group AS pgroup,
dbo.[GWCL$west_users].username,
dbo.[GWCL$west_users].uid,
dbo.[GWCL$west_users].region,
dbo.[GWCL$west_users].district
FROM dbo.[GWCL$west_users]
WHERE
dbo.[GWCL$west_users].user_group = 10
');
$users->execute();
#update and assign estimating officer
if($_POST['process']){
foreach($_POST['dm_approve'] as $id)
{
$update =$db->prepare('UPDATE dbo.[GWCL$NewServiceConnection] SET dbo.[GWCL$NewServiceConnection].staffID = '.$_POST['staffID'].', dbo.[GWCL$NewServiceConnection].dm_approve = 1 WHERE dbo.[GWCL$NewServiceConnection].Application_ID ='.$id.'');
$update->execute();
$result = $update->rowCount();
if ($result ===false) {
echo "Failed";
}else{
echo "Status " .$id. " is assigned to ".$_POST['staffID'].". <br>";
}
}
}
?>
<?php include('header.php'); ?>
<body class="with-side-menu">
<header class="site-header">
<?php require_once('topnav.php');?>
<!--.container-fluid-->
</header><!--.site-header-->
<div class="mobile-menu-left-overlay"></div>
<?php require_once('nav.php');?>
<!--.side-menu-->
<div class="page-content">
<div class="container-fluid">
<header class="section-header">
<div class="tbl">
<div class="tbl-row">
<div class="tbl-cell">
<h2>NSC Applications Pending Estimation </h2>
<div class="subtitle"><?php #echo $aName['Name'];?></div>
</div>
</div>
</div>
</header><?php if(isset($_GET['msg']))
{
$Message = "<div class='alert alert-success alert-dismissible' role='alert'>
<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span></button>
<strong>Successful!</strong> Estimation is made on Applicant's account
</div>";
echo $Message;
}?>
<section class="card">
<div class="card-block">
<div class="col-sm-4"><form name="nmc" id="wrapped" method="POST" action="assignedcust.php">
</div> <div class="col-sm-4"><select name="staffID" autofocus class="form-control" id="staffID" >
<option value="" selected>Select Estimator</option>
<?php foreach($users as $user){?>
<option value="<?php echo $user['username'];?>" ><?php echo $user['fullname'];?></option>
<?php }?>
</select></div> <input type="submit" name="process" id="submit" value="Assign" class="btn btn-primary"/>
<table id="example" class="display table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>
<input type="checkbox" class="chk_boxes" label="check all" align="left"/> Select All
</th>
<th>Applicant Name </th>
<th>Activity</th>
<th>Mobile</th>
<th>Service Type</th>
<th>Purpose</th>
<th>House Number</th>
<th>Estimate</th>
</tr>
</thead>
<tbody>
<?php foreach ($asscust as $acust){?><tr>
<td>
<input type="hidden" name="dm_approve[]" id="dm_approve[]" value="<?php echo $acust['Application_ID']; ?>">
<input type="checkbox" name="dm_approve[]" id="dm_approve[]" value="<?php echo $acust['Application_ID']; ?>" class="chk_boxes1"><?php echo $acust['Application_ID']; ?>
</td>
<td><?php echo $acust['Applicant_Name'];?></td>
<td><?php echo $acust['Activity'];?></td>
<td><?php echo $acust['Mobile_No'];?></td>
<td><?php echo $acust['Service_Category'];?></td>
<td><?php echo $acust['Purpos_Supply'];?></td>
<td><?php echo $acust['House_No'];?></td>
<td><a class="btn btn-info" href="estimater.php?ID=<?php echo $acust['Application_ID'];?>"><i class="glyphicon glyphicon-pencil"></i> Estimate</a> | <a class="btn btn-default" href="assignesti.php?ID=<?php echo $acust['Application_ID'];?>"><i class="glyphicon glyphicon-user"></i> Assign</a> </td>
</tr><?php }?>
</tbody>
</table></form>
</div>