Welcome Guest, Not a member yet? Register   Sign In
Match 2 arrays to declare selected on checkbox
#1

[eluser]ppwalks[/eluser]
Hi all,

I am trying to create an "edit" product section where they are connected through a joining table. I have one array which contains the current selected id's drawn from the joining table and I want to match that to the generated checkboxes from another array, basically if it matches the key then selected else not.

Here are my arrays:
Code:
Array ( [0] => Array ( [product_id] => 327 [product_name] => segfedsgfds [description] => 32sd2e [discounted_price] => 0.00 [price] => 0.00 [image] => imac_2.jpg [image_2] => [thumbnail] => imac_2.jpg [meta_keywords] => [meta_description] => [category_ids] => 1,4,7 [category_names] => French,Animal,Valentine's ) )

the [category_ids] are the previous selected and my generated select boxes:

So I then explode the comma separated values to create this array of selected:
Code:
Array ( [0] => 1 [1] => 4 [2] => 7 ) (Selected category ids)
Here my array that builds the categories
Code:
Array ( [0] => Array ( [category_id] => 1 [name] => French ) [1] => Array ( [category_id] => 2 [name] => Italian ) [2] => Array ( [category_id] => 3 [name] => Irish ) [3] => Array ( [category_id] => 4 [name] => Animal ) [4] => Array ( [category_id] => 5 [name] => Flower ) [5] => Array ( [category_id] => 6 [name] => Christmas ) [6] => Array ( [category_id] => 7 [name] => Valentine's ) [7] => Array ( [category_id] => 8 [name] => nick s cat ))
So where the first array contains the category ids of 1,4,7
I would like to have the checkboxes selected on those values when the check boxes are generated, any help would be greatly appreciated.

thanks

Paul



Messages In This Thread
Match 2 arrays to declare selected on checkbox - by El Forum - 08-21-2012, 04:42 AM
Match 2 arrays to declare selected on checkbox - by El Forum - 08-21-2012, 05:19 AM
Match 2 arrays to declare selected on checkbox - by El Forum - 08-21-2012, 05:20 AM
Match 2 arrays to declare selected on checkbox - by El Forum - 08-21-2012, 07:10 AM
Match 2 arrays to declare selected on checkbox - by El Forum - 08-21-2012, 08:31 AM



Theme © iAndrew 2016 - Forum software by © MyBB