Jump to content

Archived

This topic is now archived and is closed to further replies.

goatboy

checking check boxes with variables from an array

Recommended Posts

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 for
news, downloads, articles, submissions with i'd of 1-4
in my array i have 1,2,4

the 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

Share this post


Link to post
Share on other sites
When creating your checkboxes, you could do something like this:
[code]<?php
$boxes = array(1,2,4); //Populated from your SQL query
echo "<input type='checkbox' name='1' ";
if(in_array(1,$boxes)) echo "checked";
echo "/>";
?>[/code]

Share this post


Link to post
Share on other sites
[!--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 query
echo "<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

Share this post


Link to post
Share on other sites
[!--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!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.