我有一张桌子我正在尝试使用复选框更新单个列。我已经把它带到了我可以立即更新所有这些但不是一个一个的地方。我仍然是非常新的PHP所以任何帮助将不胜感激。
PHP
$tsql = "SELECT * FROM time_events WHERE Date >= '$date' and Date <
DATEADD(DAY,7,'$date') and user_id = '$employeeid' ";
try {
$getResults = $conn->prepare( $tsql);
$getResults->execute();
$rowCounter = $getResults->fetchAll(PDO::FETCH_BOTH);
} catch (Exception $ex) {
echo($ex->getMessage());
}
$count=$getResults ->rowCount();
if(isset($_POST['updatestatus'])){
for($i=0;$i<$count;$i++){
$eventid = $_POST['event_id'][$i];
if ($eventid != null){
$approved = !empty($_POST['approved'][$i]) ? 1 : 0;
$flag = isset($_POST['flag'][$i]) ? 1 : 0;
print_r ($count);
$tsql = "UPDATE time_events SET flagged = convert(int,'$flag'), approved = convert(int,'$approved') WHERE event_id = convert(int,'$eventid')";
try {
$getResults = $conn->prepare( $tsql);
$getResults->execute();
} catch (Exception $ex) {
echo($ex->getMessage());
}
}
}
}
HTML
<input type="hidden" name="event_id[]" id="event_id" value="<?php if(empty($row['event_id'])){echo null; } else {echo $row['event_id'];}; ?>"/>
<td class="col-xs-1 col-sm-1 col-md-1"><?php echo $row['day']; ?></td>
<td class="col-xs-2 col-sm-2 col-md-2"><?php echo $row['date'];?></td>
<td class="col-xs-1 col-sm-1 col-md-1"<?php echo $style; ?>><?php echo $row['start_time']; ?></td>
<td class="col-xs-1 col-sm-1 col-md-1"<?php echo $style; ?>><?php echo $row['end_time']; ?></td>
<td class="col-xs-1 col-sm-1 col-md-1"<?php echo $style; ?>><?php echo $row['job_number']; ?></td>
<td class="col-xs-4 col-sm-4 col-md-4"<?php echo $style; ?>><?php echo $row['description']; ?></td>
<td class="col-xs-1 col-sm-1 col-md-1 text-center"><input type="checkbox" class="chk_boxes1" name="flag[]" value="<?php echo $row['event_id']; ?>" title="Flag Time Entry" <?php if ($row['flagged'] == 1) echo "checked='checked'"; ?></input ></td>
<td class="col-xs-1 col-sm-1 col-md-1 text-center"><input type="checkbox" class="chk_boxes2" name="approved[]" value="<?php echo $row['event_id']; ?>" title="Approve Time Entry" <?php if ($row['approved'] == 1) echo "checked='checked'"; ?></input></td>