goatboy Posted June 20, 2006 Share Posted June 20, 2006 this is for a screen where i'm editing a user.I'm able to assign the user access to certain sections. to do this in the user setup i use checkboxes.i put the selections into an array and then serialize them before entering it into a database.when i go to edit the user, getting the array out isn't the issue. i unserialize it. but i want the checkboxes checked according to whats in the array.so lets say i have check boxes fornews, downloads, articles, submissions with i'd of 1-4in my array i have 1,2,4the problem i'm having is how do i compare the checkbox id to the i'ds in the array so it will be checked if one of them matches. btw the options for check boxes will get longer in the future.I hope i explained this well enough and didn't make it too confusing Quote Link to comment https://forums.phpfreaks.com/topic/12475-checking-check-boxes-with-variables-from-an-array/ Share on other sites More sharing options...
zq29 Posted June 20, 2006 Share Posted June 20, 2006 When creating your checkboxes, you could do something like this:[code]<?php$boxes = array(1,2,4); //Populated from your SQL queryecho "<input type='checkbox' name='1' ";if(in_array(1,$boxes)) echo "checked";echo "/>";?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/12475-checking-check-boxes-with-variables-from-an-array/#findComment-47804 Share on other sites More sharing options...
goatboy Posted June 29, 2006 Author Share Posted June 29, 2006 [!--quoteo(post=386158:date=Jun 20 2006, 04:53 PM:name=SemiApocalyptic)--][div class=\'quotetop\']QUOTE(SemiApocalyptic @ Jun 20 2006, 04:53 PM) [snapback]386158[/snapback][/div][div class=\'quotemain\'][!--quotec--]When creating your checkboxes, you could do something like this:[code]<?php$boxes = array(1,2,4); //Populated from your SQL queryecho "<input type='checkbox' name='1' ";if(in_array(1,$boxes)) echo "checked";echo "/>";?>[/code][/quote]ah that looks like it will work, and i can just replace the numeric values with the id variable from the database Quote Link to comment https://forums.phpfreaks.com/topic/12475-checking-check-boxes-with-variables-from-an-array/#findComment-51026 Share on other sites More sharing options...
goatboy Posted June 29, 2006 Author Share Posted June 29, 2006 [!--quoteo(post=389463:date=Jun 29 2006, 04:25 PM:name=goatboy)--][div class=\'quotetop\']QUOTE(goatboy @ Jun 29 2006, 04:25 PM) [snapback]389463[/snapback][/div][div class=\'quotemain\'][!--quotec--]ah that looks like it will work, and i can just replace the numeric values with the id variable from the database[/quote]works! Quote Link to comment https://forums.phpfreaks.com/topic/12475-checking-check-boxes-with-variables-from-an-array/#findComment-51029 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.