Reputation: 43
I have a page with 100 checkboxes.. on and off. These checkboxes are named "box1" "box2" "box3" etc. They are pulled from a single row/col in a table where I exploded 1|0|1|0|1 into individual checkbox inputs.
My issue is that when I try to update them, I can't figure out how I can get them back into a single string to put them back into the same column. Here is what I have.. but clearly it doesn't work. Some of this stuff is new to me. Any advice would help.
$i = 1;
while($i < 101){
$thisBox = $_POST['box'][$i];
if($thisBox != 1){$thisBox = 0;}
$boxData .= $thisBox . "|";
$i++;
}
It just shows up with 100x "|" and I am unsure if it's possible to create the $_POST['box##']
with each loop.
Upvotes: 0
Views: 33
Reputation: 11987
try this,
$thisBox = $_POST["box$i"] == "on" ? 1 : 0;
$boxData .= $thisBox . "|";
No need of if
condition
Upvotes: 1