hi there,
I am trying to use bitwise operator in implementing checkbox (multiple selection) in a form, here is the code below in the form:
<tr><td>Intended purpose of Car :</td><td><input type=checkbox name=object[pros_buypurpose][] value=1 ".(($object['pros_buypurpose']&1)?'checked':'').">Personal use<br>
<input type=checkbox name=object[pros_buypurpose][] value=2 ".(($object['pros_buypurpose']&2)?'checked':'').">Family use<br>
<input type=checkbox name=object[pros_buypurpose][] value=3 ".(($object['pros_buypurpose']&3)?'checked':'').">Business<br></td></tr>
in the submit portion, i check it like this:
$buy_purpose = 0;
for ($i=0; $i<count($object['pros_buypurpose']); $i++) {
$buy_purpose = $buy_purpose | $object['pros_buypurpose'][$i];
}
unset($object['pros_buypurpose']);
$object['pros_buypurpose'] = $buy_purpose;
.........
while (list($key, $val) = each($object)) {
.....
}
After i insert to the database, and check back the value (selection of that checkbox), it turn out to be different from the one that i checked for the first time. Any ideas?
Thanks in-advanced!