1
複選框有更新表單,所以我需要,如果某些複選框輸入已經根據MySQL數據進行檢查,那麼它會顯示檢查。複選框檢查MySQL數據的逗號(,)
<?php
$statement = $db->prepare("SELECT leavingEquipment FROM orderform WHERE orderNo='$orderNo'"); // here are the checked data
$statement->execute();
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
foreach($result as $row4){
$leavingEquipment = explode(", ",$row4['leavingEquipment']); // Here I use explode I check this with var_dump
$statement = $db->prepare("SELECT * FROM equipment"); // here all equipment
$statement->execute();
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
foreach($result as $row3) {
$leavingEquipment3=$row3['equipmentTitle'];
?>
<input type="checkbox" name="leavingEquipment[]" value="<?php echo $row3['equipmentTitle']; ?>" <?php if($leavingEquipment==$leavingEquipment3) echo 'checked'; ?>><label class="control-label"><?php echo $row3['equipmentTitle']; ?></label>
<?php
}
}
?>
Var_dum輸出這樣的: 陣列(2){[0] =>串(9) 「藍牙」 1 =>串(6) 「殼體」}
感謝。
長閉括號是錯誤的。 –
感謝它的工作..很多很多謝謝 –
@AmranurRahman你非常歡迎! :-) –