fesan Posted March 24, 2009 Share Posted March 24, 2009 Hello.... I'll try to explain this in a easy way. Take a look at this link. This is the page to create a group. Log in on the left side using username "test" and password "test" http://www.fesan.cc/utvikling/dlight/index.php?page=create_group In the action script the check box values are imploded and added to a database. On another page i want to edit the info in a selected group. So I want to have the exact same output on the page but the values that earlier was created when making the group is supposed to be filled out. You can try out this page and see that the "Gruppe Navn:" and "Gruppe Beskrivelse:" filled out with the values in the group. http://www.fesan.cc/utvikling/dlight/index.php?page=change_group&id=5&gruppe=Ny_test Now the thing a want to achieve is to make the check boxes an the right side to be checked if they are selected when creating the group. Can i do this without making a HUGE if elseif statement using the explode? I also expect the number of checkboxes will extend with time... PS: Sorry but the page is in Norwegian! Thanks in advance for any replies! Quote Link to comment https://forums.phpfreaks.com/topic/150878-explode/ Share on other sites More sharing options...
Daniel0 Posted March 24, 2009 Share Posted March 24, 2009 Looks like you have other problems on your website as well (see attached screenshot). I suppose you're getting the text from a database and using a wrong collation. You need to use the same character set throughout your entire application, that's to say you need to save your files in that charset, you need to tell the client which charset it is and your database has to be in that charset. Anyway, that's not relevant to your problem in this topic. Just thought I'd point it out. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/150878-explode/#findComment-792611 Share on other sites More sharing options...
fesan Posted March 24, 2009 Author Share Posted March 24, 2009 Yes i know.... that is my private page which I'm currently making huge changes to. The project has had a pause for some time now. Allot of work! Just using my domain to develop this database for my job. But thanks anyway! Quote Link to comment https://forums.phpfreaks.com/topic/150878-explode/#findComment-792616 Share on other sites More sharing options...
rhodesa Posted March 24, 2009 Share Posted March 24, 2009 i usually do: <?php $options = array( 1 => 'First Checkbox', 2 => 'Second Checkbox', 3 => 'Third Checkbox', 4 => 'Fourth Checkbox', 5 => 'Fifth Checkbox', 6 => 'Sixth Checkbox', ); $value = "1,4,5,6"; //This is the value from your DB $choices = explode(',',$value);//Now we have an array foreach($options as $k => $v){ print '<input type="checkbox" name="foobar[]" value="'.htmlspecialchars($k).'" '; if(in_array($k,$choices)) print 'CHECKED'; print '/>'.htmlspecialchars($v).'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/150878-explode/#findComment-792621 Share on other sites More sharing options...
fesan Posted March 24, 2009 Author Share Posted March 24, 2009 This is Awesome!!! Thank you rhodesa!!! I have to start learning this "as" and "=>" things... seams to make life a lot easier! Quote Link to comment https://forums.phpfreaks.com/topic/150878-explode/#findComment-792632 Share on other sites More sharing options...
rhodesa Posted March 24, 2009 Share Posted March 24, 2009 http://www.php.net/foreach http://devzone.zend.com/node/view/id/635#Heading6 Quote Link to comment https://forums.phpfreaks.com/topic/150878-explode/#findComment-792637 Share on other sites More sharing options...
fesan Posted April 6, 2009 Author Share Posted April 6, 2009 Hello.... Busy times and haven't had a Chance too look at it before now. Had to modify the script a bit to get it to work... it looked like this in the end: <?php $options = array( 1 => $row['0'], ); $value = $row['list_include']; $choices = explode(',',$value); foreach($options as $k => $v){ print '<label><input type="checkbox" name="foobar[]" value="'.htmlspecialchars($v).'" '; if(in_array($v,$choices)) print 'checked="checked"'; print '/>'. htmlspecialchars($v). '</label><br>'; } ?> Thanks again for the help... Just wonder about one thing. This is not the right place too ask but i hope for an answer anyway. If a field in a form is disabled like this: <input type='checkbox' name='checkbox[]' value='id' id='id' checked='checked' disabled='disabled'> Does the value still post trough to the action script? Quote Link to comment https://forums.phpfreaks.com/topic/150878-explode/#findComment-802633 Share on other sites More sharing options...
rhodesa Posted April 6, 2009 Share Posted April 6, 2009 Just wonder about one thing. This is not the right place too ask but i hope for an answer anyway. If a field in a form is disabled like this: <input type='checkbox' name='checkbox[]' value='id' id='id' checked='checked' disabled='disabled'> Does the value still post trough to the action script? i don't believe so Quote Link to comment https://forums.phpfreaks.com/topic/150878-explode/#findComment-802644 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.