izbryte Posted December 19, 2007 Share Posted December 19, 2007 I am trying to allow editing in an admin section. I have several checkboxes where the user can check one or more of a category which are then sent to a database using the serialize function. I would like the admin to be able to pull up the entire list of checkboxes showing the ones that were previously checked. So here's what I have that doesn't work: the array: $array1 = array ('option1,'option2','option3'); then the rest $choice = unserialize($row['choice']); foreach ($array1 as $value) { echo '<input type="checkbox" name="option[]" value="' . $value . '"'; if ($value == $option) { echo ' checked'; }'; } Do this make sense? As of now the checkboxes show but the previously "checked" ones are not checked. Quote Link to comment https://forums.phpfreaks.com/topic/82251-need-help-with-2-arrays/ Share on other sites More sharing options...
rab Posted December 19, 2007 Share Posted December 19, 2007 Where is $option defined? Do you mean $choice? Also make it if ($value == $option) { echo ' checked'; } You had a '; at the end brace Quote Link to comment https://forums.phpfreaks.com/topic/82251-need-help-with-2-arrays/#findComment-418067 Share on other sites More sharing options...
papaface Posted December 19, 2007 Share Posted December 19, 2007 You havent ended your input tag's > Quote Link to comment https://forums.phpfreaks.com/topic/82251-need-help-with-2-arrays/#findComment-418069 Share on other sites More sharing options...
izbryte Posted December 19, 2007 Author Share Posted December 19, 2007 Where is $option defined? Do you mean $choice? Also make it if ($value == $option) { echo ' checked'; } You had a '; at the end brace Yes sorry, I think I'm losing it... LOL it should be choice = unserialize($row['choice']); $choice = unserialize($row['choice']); foreach ($array1 as $value) { echo '<input type="checkbox" name="option[]" value="' . $value . '"'; if ($value == $choice) { echo ' checked'; } echo '>'; } Quote Link to comment https://forums.phpfreaks.com/topic/82251-need-help-with-2-arrays/#findComment-418080 Share on other sites More sharing options...
izbryte Posted December 19, 2007 Author Share Posted December 19, 2007 ??? anyone Quote Link to comment https://forums.phpfreaks.com/topic/82251-need-help-with-2-arrays/#findComment-418927 Share on other sites More sharing options...
PHP_PhREEEk Posted December 20, 2007 Share Posted December 20, 2007 I'm going to admit that I have absolutely -no- idea what's really going on here... heh I'll take a stab, tho, because this problem is fading down the list... If my solution isn't a solution, it might get you headed the right way, so here we go... Could you maybe be needing to compare the key against choice for the 'checked' portion? $choice = unserialize($row['choice']); foreach ($array1 as $key => $value) { echo '<input type="checkbox" name="option[]" value="' . $value . '"'; if ($key == $choice) { echo ' checked'; } echo '>'; } Whether or not this works, I have no idea why this is being done... serialize wasn't really purposed for storing an array into a database in this manner. This defeats the reason behind having a normalized database with atomic values. I would much prefer to fix the logic behind the database structure, and this problems disappears forever. I can't be of much help there, as the 'bigger picture' of what you're doing isn't here, just this snippet... just some thoughts. = ) PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/82251-need-help-with-2-arrays/#findComment-419257 Share on other sites More sharing options...
izbryte Posted December 20, 2007 Author Share Posted December 20, 2007 I'm sure that this could be set up better... LOL. Basically I have a form that people fill out (name, address, email, etc) and then they have have to check all their specialties using checkboxes. All this info gets put into a database. I'm using the serialize function to handle the checked info. Now I'm creating a form where admin can edit this information if needed. So, I'm trying to basically re-create the form with the previous entered values showing. So the name textbox shows the value entered for name, email textbox shows the email address entered, etc.... and all the checkboxes show up with the previously checked ones checked. Does that help at all? Quote Link to comment https://forums.phpfreaks.com/topic/82251-need-help-with-2-arrays/#findComment-419625 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.