I am currently stuck at posting checkboxes that haven't been checked and require your help. The following is the code I am currently using.
PHP
while($select_info2 = mysqli_fetch_assoc($select_info1)){
$n='1';
echo "<tr>";
echo "<td>".$select_info2['Device_DNS_name']."</td>";
echo "<td>".$select_info2['Uplink_port']."</td>";
echo "<td>".$select_info2['VLAN']."</td>";
echo "<td>".$select_info2['Teamed_network']."</td>";
echo "<td>".$select_info2['Teamed_description']."</td>";
for($a = $select_detailed_dns2['starting_port']; $a <= $select_detailed_dns2['ending_port']; $a++ ){
if('10' > $a){
if ($select_info2["port-0".$a] == "1" || $select_info2["port-0".$a] == "01" ){
$check ='checked="checked"';
}else{
$check = '';
}
?>
<td><input type="checkbox" name="check_<?php echo $select_info2['ID']."[]"?>" id="check_<?php echo $select_info2['ID']?>" <?php echo $check ?> value = "On" /></td>
<?php
}else{
if ($select_info2["port-".$a] == "1" || $select_info2["port-".$a] == "1" ){
$check ='checked="checked"';
}else{
$check = '';
}
?>
<td><input type="checkbox" name="check_<?php echo $select_info2['ID']."[]"?>" id="check_<?php echo $select_info2['ID']?>" <?php echo $check ?> value = "On" /></td>
<?php
}
}
?>
<td><input type="button" name="Check_All" value="Check All" onClick="CheckAll(document.checktable.check_<?php echo $select_info2['ID']?>)"> </td>
<td><input type="button" name="Un_Check_All" value="Uncheck All" onClick="UnCheckAll(document.checktable.check_<?php echo $select_info2['ID']?>)"> </td>
<td><input type="submit" name="update_row" value="Update Row" > </td>
<?php
echo "</tr>";
}
The above code generates checkboxes depending how many columns there are in the table in the database. You may be asking why the name is an array format. This is so that I can POST all values. You may also be asking why the id is the same and not different. This is so that I can target an entire row to check or uncheck. The below is how I am currently outputting all checked checkboxes:
<?php
if(isset($_POST['update_row'])){
$c1 = $_POST['check_1'];
var_dump($c1);
}
?>
Generated HTML
<td><input type="checkbox" name="check_1[]" id="check_1" value = "1" /></td>
<td><input type="checkbox" name="check_1[]" id="check_1" value = "1" /></td>
<td><input type="checkbox" name="check_1[]" id="check_1" value = "1" /></td>
<td><input type="checkbox" name="check_1[]" id="check_1" value = "1" /></td>
<td><input type="checkbox" name="check_1[]" id="check_1" value = "1" /></td>
<td><input type="checkbox" name="check_1[]" id="check_1" value = "1" /></td>
<td><input type="checkbox" name="check_1[]" id="check_1" value = "1" /></td>
<td><input type="checkbox" name="check_1[]" id="check_1" value = "1" /></td>
<td><input type="checkbox" name="check_1[]" id="check_1" value = "1" /></td>
<td><input type="checkbox" name="check_1[]" id="check_1" value = "1" /></td>
<td><input type="checkbox" name="check_1[]" id="check_1" value = "1" /></td>
<td><input type="checkbox" name="check_1[]" id="check_1" value = "1" /></td>
<td><input type="checkbox" name="check_1[]" id="check_1" value = "1" /></td>
<td><input type="checkbox" name="check_1[]" id="check_1" value = "1" /></td>
<td><input type="checkbox" name="check_1[]" id="check_1" value = "1" /></td>
<td><input type="checkbox" name="check_1[]" id="check_1" value = "1" /></td>
<td><input type="checkbox" name="check_1[]" id="check_1" value = "1" /></td>
<td><input type="checkbox" name="check_1[]" id="check_1" value = "1" /></td>
<td><input type="checkbox" name="check_1[]" id="check_1" value = "1" /></td>
<td><input type="checkbox" name="check_1[]" id="check_1" value = "1" /></td>
<td><input type="checkbox" name="check_1[]" id="check_1" value = "1" /></td>
<td><input type="checkbox" name="check_1[]" id="check_1" value = "1" /></td>
<td><input type="checkbox" name="check_1[]" id="check_1" value = "1" /></td>
<td><input type="checkbox" name="check_1[]" id="check_1" value = "1" /></td>
<td><input type="button" name="Check_All" value="Check All" onClick="CheckAll(document.checktable.check_1)"> </td>
<td><input type="button" name="Un_Check_All" value="Uncheck All" onClick="UnCheckAll(document.checktable.check_1)"> </td>
<td><input type="submit" name="update_row" value="Update Row" > </td>
</tr><tr><td>HEPSAN03</td><td>No</td><td>NET44</td><td>No</td><td></td> <td><input type="checkbox" name="check_2[]" id="check_2" value = "1" /></td>
<td><input type="checkbox" name="check_2[]" id="check_2" value = "1" /></td>
<td><input type="checkbox" name="check_2[]" id="check_2" value = "1" /></td>
<td><input type="checkbox" name="check_2[]" id="check_2" value = "1" /></td>
<td><input type="checkbox" name="check_2[]" id="check_2" value = "1" /></td>
<td><input type="checkbox" name="check_2[]" id="check_2" value = "1" /></td>
<td><input type="checkbox" name="check_2[]" id="check_2" value = "1" /></td>
<td><input type="checkbox" name="check_2[]" id="check_2" value = "1" /></td>
<td><input type="checkbox" name="check_2[]" id="check_2" value = "1" /></td>
<td><input type="checkbox" name="check_2[]" id="check_2" value = "1" /></td>
<td><input type="checkbox" name="check_2[]" id="check_2" value = "1" /></td>
<td><input type="checkbox" name="check_2[]" id="check_2" value = "1" /></td>
<td><input type="checkbox" name="check_2[]" id="check_2" value = "1" /></td>
<td><input type="checkbox" name="check_2[]" id="check_2" value = "1" /></td>
<td><input type="checkbox" name="check_2[]" id="check_2" value = "1" /></td>
<td><input type="checkbox" name="check_2[]" id="check_2" value = "1" /></td>
<td><input type="checkbox" name="check_2[]" id="check_2" value = "1" /></td>
<td><input type="checkbox" name="check_2[]" id="check_2" value = "1" /></td>
<td><input type="checkbox" name="check_2[]" id="check_2" value = "1" /></td>
<td><input type="checkbox" name="check_2[]" id="check_2" value = "1" /></td>
<td><input type="checkbox" name="check_2[]" id="check_2" value = "1" /></td>
<td><input type="checkbox" name="check_2[]" id="check_2" value = "1" /></td>
<td><input type="checkbox" name="check_2[]" id="check_2" value = "1" /></td>
<td><input type="checkbox" name="check_2[]" id="check_2" value = "1" /></td>
<td><input type="button" name="Check_All" value="Check All" onClick="CheckAll(document.checktable.check_2)"> </td>
<td><input type="button" name="Un_Check_All" value="Uncheck All" onClick="UnCheckAll(document.checktable.check_2)"> </td>
<td><input type="submit" name="update_row" value="Update Row" > </td>
</tr><tr><td>HEPSAN03</td><td>No</td><td>PRIV44</td><td>No</td><td></td> <td><input type="checkbox" name="check_4[]" id="check_4" value = "1" /></td>
<td><input type="checkbox" name="check_4[]" id="check_4" value = "1" /></td>
<td><input type="checkbox" name="check_4[]" id="check_4" value = "1" /></td>
<td><input type="checkbox" name="check_4[]" id="check_4" value = "1" /></td>
<td><input type="checkbox" name="check_4[]" id="check_4" value = "1" /></td>
<td><input type="checkbox" name="check_4[]" id="check_4" value = "1" /></td>
<td><input type="checkbox" name="check_4[]" id="check_4" value = "1" /></td>
<td><input type="checkbox" name="check_4[]" id="check_4" value = "1" /></td>
<td><input type="checkbox" name="check_4[]" id="check_4" value = "1" /></td>
<td><input type="checkbox" name="check_4[]" id="check_4" value = "1" /></td>
<td><input type="checkbox" name="check_4[]" id="check_4" value = "1" /></td>
<td><input type="checkbox" name="check_4[]" id="check_4" value = "1" /></td>
<td><input type="checkbox" name="check_4[]" id="check_4" value = "1" /></td>
<td><input type="checkbox" name="check_4[]" id="check_4" value = "1" /></td>
<td><input type="checkbox" name="check_4[]" id="check_4" value = "1" /></td>
<td><input type="checkbox" name="check_4[]" id="check_4" value = "1" /></td>
<td><input type="checkbox" name="check_4[]" id="check_4" value = "1" /></td>
<td><input type="checkbox" name="check_4[]" id="check_4" value = "1" /></td>
<td><input type="checkbox" name="check_4[]" id="check_4" value = "1" /></td>
<td><input type="checkbox" name="check_4[]" id="check_4" value = "1" /></td>
<td><input type="checkbox" name="check_4[]" id="check_4" value = "1" /></td>
<td><input type="checkbox" name="check_4[]" id="check_4" value = "1" /></td>
<td><input type="checkbox" name="check_4[]" id="check_4" value = "1" /></td>
<td><input type="checkbox" name="check_4[]" id="check_4" value = "1" /></td>
<td><input type="button" name="Check_All" value="Check All" onClick="CheckAll(document.checktable.check_4)"> </td>
<td><input type="button" name="Un_Check_All" value="Uncheck All" onClick="UnCheckAll(document.checktable.check_4)"> </td>
<td><input type="submit" name="update_row" value="Update Row" > </td>
</tr><tr><td>HEPSAN03</td><td>No</td><td>NET40</td><td>No</td><td></td> <td><input type="checkbox" name="check_5[]" id="check_5" value = "1" /></td>
<td><input type="checkbox" name="check_5[]" id="check_5" value = "1" /></td>
<td><input type="checkbox" name="check_5[]" id="check_5" value = "1" /></td>
<td><input type="checkbox" name="check_5[]" id="check_5" value = "1" /></td>
<td><input type="checkbox" name="check_5[]" id="check_5" value = "1" /></td>
<td><input type="checkbox" name="check_5[]" id="check_5" value = "1" /></td>
<td><input type="checkbox" name="check_5[]" id="check_5" value = "1" /></td>
<td><input type="checkbox" name="check_5[]" id="check_5" value = "1" /></td>
<td><input type="checkbox" name="check_5[]" id="check_5" value = "1" /></td>
<td><input type="checkbox" name="check_5[]" id="check_5" value = "1" /></td>
<td><input type="checkbox" name="check_5[]" id="check_5" value = "1" /></td>
<td><input type="checkbox" name="check_5[]" id="check_5" value = "1" /></td>
<td><input type="checkbox" name="check_5[]" id="check_5" value = "1" /></td>
<td><input type="checkbox" name="check_5[]" id="check_5" value = "1" /></td>
<td><input type="checkbox" name="check_5[]" id="check_5" value = "1" /></td>
<td><input type="checkbox" name="check_5[]" id="check_5" value = "1" /></td>
<td><input type="checkbox" name="check_5[]" id="check_5" value = "1" /></td>
<td><input type="checkbox" name="check_5[]" id="check_5" value = "1" /></td>
<td><input type="checkbox" name="check_5[]" id="check_5" value = "1" /></td>
<td><input type="checkbox" name="check_5[]" id="check_5" value = "1" /></td>
<td><input type="checkbox" name="check_5[]" id="check_5" value = "1" /></td>
<td><input type="checkbox" name="check_5[]" id="check_5" value = "1" /></td>
<td><input type="checkbox" name="check_5[]" id="check_5" value = "1" /></td>
<td><input type="checkbox" name="check_5[]" id="check_5" value = "1" /></td>
<td><input type="button" name="Check_All" value="Check All" onClick="CheckAll(document.checktable.check_5)"> </td>
<td><input type="button" name="Un_Check_All" value="Uncheck All" onClick="UnCheckAll(document.checktable.check_5)"> </td>
<td><input type="submit" name="update_row" value="Update Row" > </td>
</tr>
Hope you can Help Thank You