Forum Moderators: coopster
$pmethods = explode("¦¦", $r2["PaymentMethods"]);
$choices = array('1'=>"Cashiers Check",'2' => "Money Order",'3'=>"Personal Check",'4'=>"Credit Card",'8'=>"PayPal");
foreach ($choices as $key6 => $value6) {
$checked = ($pmethods == $key6) ? ' checked="checked"' : '';
echo "<input type=\"checkbox\" name=\"methods[]\" value=\"$key6\" $checked />$value6";
echo "</br>";
}
This only shows the checkboxes and none of them checked.
My other attempt has been:
foreach ($pmethods as $key => $value2) {
if ($value2=="10"){
print "<input type=\"checkbox\" name=\"methods[]\" value=\"Cash\" checked=\"checked\" />Cash";
}
if (($value2=="1") OR ($value2=="3")){
print "<input type=\"checkbox\" name=\"methods[]\" value=\"Check\" checked=\"checked\" />Check";
}
if ($value2=="2"){
print "<input type=\"checkbox\" name=\"methods[]\" value=\"Money Order\" checked=\"checked\" />Money Order";
}
if (($value2=="4") OR ($value2=="5") OR ($value2=="6") OR ($value2=="7")){
print "<input type=\"checkbox\" name=\"methods[]\" value=\"Credit Card\" checked=\"checked\" />Credit Card";
}
if ($value2=="8"){
print "<input type=\"checkbox\" name=\"methods[]\" value=\"Paypal\" checked=\"checked\" />PayPal";
}
}
The problem with this method is that it only shows the checked boxes and not the unchecked ones which need to be shown as well.
Any help would be appreciated. Thanks.
you just need to move your if statement. You want to always show the checkbox but only check it if it is checked. So the portion of the checkbox html that makes it appear checked is all you need to surround with an if
print "<input type=\"checkbox\" name=\"methods[]\" value=\"Paypal\";
if ($value2=="8") echo ' checked="checked"';
echo " />PayPal";
}
something like that