Save and load multiple checks using php power() function

Asked 2 years ago, Updated 2 years ago, 35 views

Hi, everyone. When handing it over to DB, I used pow() to hand it over, but I didn't know how to get it, so I registered the question ㅠ<

<label><input name="attention[]"value="1" type="checkbox"><span>ga</span><
<label><input name="attention[]"value="2" type="checkbox"><span>Me</span></label>
<label><input name="attention[]"value="3" type="checkbox"><span>Da</span></label>
<label><input name="attention[]"value="4" type="checkbox"><span>La</span></label>

<input name="att" value="" type="hidden">

If there's a cord like this


 var att= '';
 $joinForm.find('[name="attention[]"]:checked').each(function(){
       att+= +Math.pow(2, $(this).val());
  });

I send the usePlace value from here to DB and check it, but I don't know what to do with getting it; Even when I get it

--table--
user    |attention    
==================
test1   |24816

$check = $result->attention;
for($i=0;$i<4;$i++){
    $check -= pow($i,2)
}

I did it, and it's not working out as I expected. What should I do? ㅠ<

php laravel

2022-09-22 12:25

1 Answers

I wonder why I have to verify the bit operation here.

If you save it in mysql without any js processing in this state, the attention field will be comma-separated values, for example "1,3,4". Why don't you just take that and do what you want.

$attentions = implode(',', $result->attention);
foreach ([1, 2, 3, 4] as $attentionOptions) {
    If(!in_array($attentionOptions,$attentionOptions)echo 'Huck' .$attentionOptions' was not checked';
}

If you have to verify the bit operation... Replace var attr='; with var attr=0; in the js-level code you uploaded.


2022-09-22 12:25

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.