Home > Blockchain >  PHP: How to check more then one row for check a checkbox
PHP: How to check more then one row for check a checkbox

Time:10-11

I would like to check a checkbox if I have integer 1 stored in row a or b.

For now I created a working version to check for row 'a'. How can I check also for row 'b'? So as said above if row a or/and b has integer 1 stored check the checkbox.

<input type="checkbox" name="a" id="a" value="1" <?php if($row['a'] == "1") { echo "checked"; }?>>

CodePudding user response:

This should work for you. this will echo checked to make the checkbox checked if any of the row contains integer 1

<?php ($row['a'] == 1 || $row['b'] == 1) ? 'checked':''; ?>

CodePudding user response:

$checked = array('','checked');

$row['a'] = 1;
$row['b'] = 0;

echo 'Row A<input type="checkbox" name="a" id="a" value="1"' . $checked[$row['a']] . ' /><br>';
echo 'Row B<input type="checkbox" name="b" id="b" value="1"' . $checked[$row['b']] . ' /><br>';
echo 'Row A or B<input type="checkbox" name="ab" id="ab" value="1"' . $checked[$row['a'] | $row['b']]   . ' />';

enter image description here

  • Related