darshanpm Posted February 9, 2009 Share Posted February 9, 2009 Hi Friends, I have a form with list of checkboxes that are generated dynamically based on other table in mysql. I save the selected checkbox values in mysql table as a string separated with , (1,2,3,4,5). Now, i want people to edit the form again. It will load the other values of the form and the checkboxes, but i want to have the checkboxes selected which were selected and saved in mysql. Hope i am clear about what i am looking to do. So, i want to retrieve the checkbox values (1,2,3,4,5) which i have stored earlier and then check against all the checkboxes and selecting them if the value exists in the array. Can anyone help me to do this and provide me some sample code or tutorial link. Thanks, Darshan Link to comment https://forums.phpfreaks.com/topic/144437-phpmysql-checkbox-arrays/ Share on other sites More sharing options...
flyhoney Posted February 9, 2009 Share Posted February 9, 2009 <?php $options_from_db = '1,2,3,4,5'; $values = explode(',', $string); $all_options = array(1, 2, 3, 4, 5, 6, 7, 8, 9); foreach ($all_options as $option) { echo '<input type="checkbox" name="values[]" value="' . $option . '" ' . ((in_array($option, $options_from_db)) ? 'checked="checked"' : '') . '/>'; } ?> Link to comment https://forums.phpfreaks.com/topic/144437-phpmysql-checkbox-arrays/#findComment-757947 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.