jquery - How to set values in checkbox using php array and Mysql -


i want set values in checkbox using array , values fetched database. have string 1,2,3,6,8 has been converted string using explode function. fetched values database has 10 elements has item_id 1 , on. want compare values array 1 one , matches value, checkbox checked , if not checkbox remain unchecked. total checkbox 10. 5 should selected per item_id , array.

$string = 1,2,3,6,8; $array = explode(',', $string); 

$string = "1,2,3,6,8"; $values = explode(',', $string); for($i=1;$i<=10;$i++) {   if(in_array($i,$values))    echo "<input type='checkbox' name='checkboxes[]' value='$i' checked='checked'>";   else    echo "<input type='checkbox' name='checkboxes[]' value='$i'>"; } 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -