jamkelvl Posted February 2, 2010 Share Posted February 2, 2010 Okay, so have a list of checkboxes that store in a serialized array and then to database. I'm wondering, if at all possible, how to store a value in the array if one or more checkboxes have not been checked. Basically, if one checkboxe is checked it stores in the array fine, but as for the rest of the uncheckedboxes I want to store a value in the array such as x for each uncheckedbox. Here is my code thus far <?php if (in_array($initials, $_POST['assignedTo'])) { // do nothing } else { echo '<p>'.$name.'<input type="checkbox" name="assignedTo[]" id="assignedTo" value="'.$initials.'" style="margin-right: 75%; float: right;" /><br/>'; echo '<input type="text" name="assignedTo[]" id="'.$name.'" value="0" onFocus="startCalc();" onBlur="stopCalc();" /></p>'; } foreach ($_POST['assignedTo'] as $value) { if ($value == $initials) { echo '<p>'.$name.'<input type="checkbox" name="assignedTo[]" id="assignedTo" style="margin-right: 75%; float: right;" value="'.$initials.'" checked />'; echo '<input type="text" name="assignedTo[]" id="'.$name.'" value="0" onFocus="startCalc();" onBlur="stopCalc();" /></p>'; } } ?> Link to comment https://forums.phpfreaks.com/topic/190662-checkboxes-array-selected/ Share on other sites More sharing options...
gwolgamott Posted February 2, 2010 Share Posted February 2, 2010 nest some if to do that.... here some sudo code if ($box == CHECKED) $array[$i] = $my_info; else{ $array[$i] = 'X'; } Link to comment https://forums.phpfreaks.com/topic/190662-checkboxes-array-selected/#findComment-1005500 Share on other sites More sharing options...
jamkelvl Posted February 2, 2010 Author Share Posted February 2, 2010 Hmm.. yeah I ended up coming up with a bandaid. Basically, before inserting into database, I loop thru the array and add a new value 'x' before each value... errraa something along those lines. Either way.. it works...for now. <?php $newArray = array(); //padd x's into array foreach ($_POST['assignedTo'] as $value) { // if initials, hour value MUST be set // puts initial, iterates again and puts value, if its 0 this will MESSSS UPPP as it adds an x if ($value == '0') { $newArray[] = 'x'; $newArray[] = $value; } else { $newArray[] = $value; } } $sNewArray = serialize($newArray); ?> Link to comment https://forums.phpfreaks.com/topic/190662-checkboxes-array-selected/#findComment-1005552 Share on other sites More sharing options...
gwolgamott Posted February 2, 2010 Share Posted February 2, 2010 Not a bandaid... that's sort of what I was suggestioning anyways. Part science, part art, and part trying to make a square block fit into the circle hole... round the edges until it fits... then it fits... not efficient but if you don't have time to cut a new block like you should have to begin with to fit then trim the one you have. I love programming inefficiently makes me feel warm inside. haha... but it also makes your head hurt when you have to deal with it later... Link to comment https://forums.phpfreaks.com/topic/190662-checkboxes-array-selected/#findComment-1005561 Share on other sites More sharing options...
jamkelvl Posted February 16, 2010 Author Share Posted February 16, 2010 Lol, yes. I have since had to deal with this SEVERAL times, still using the same old "band-aid" though ... only... I have had to create SEVERAL MORE Link to comment https://forums.phpfreaks.com/topic/190662-checkboxes-array-selected/#findComment-1012965 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.