Solved

Build select menus based on this array

Posted on 2008-10-18
1
171 Views
Last Modified: 2008-10-21
Ok, so I want to create the following two select menus based on the following array:

<select name="size">
<option value="X879">small / medium</option>
<option value="7ABC">small / large </option>
</select>

<select name="quantity">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
Array

(

    [size] => Array

        (

			[X879] => Array

			(

				[0] => Array

				(

		            [item_id] => 32

		            [value] => small

		            [id] => 2

		            [aid] => 10

				)

				

				[1] => Array

				(

		            [item_id] => 32

		            [value] => medium

		            [id] => 2

		            [aid] => 14

				)

			)

			

			[7ABC] => Array

			(

				[0] => Array

				(

		            [item_id] => 32

		            [value] => small

		            [id] => 2

		            [aid] => 10

				)

				

				[1] => Array

				(

		            [item_id] => 32

		            [value] => large

		            [id] => 2

		            [aid] => 130 

				)

			)

        )
 

    [quantity] => Array

        (

            [options] => Array

			(

				[1] => Array

				(

					num => 1

				)

				

				[2] => Array

				(

					num => 2

				)

				

				[3] => Array

				(

					num => 3

				)

			)

        )

)

Open in new window

0
Comment
Question by:n00b0101
1 Comment
 
LVL 16

Accepted Solution

by:
sh0e earned 500 total points
ID: 22749101

//code may need cleaning up

foreach ($sel_arr as $sel_name => $opt_arr) {

	echo "<select name=\"{$sel_name}\"";

    if(strcmp($sel_name, "size")==0)

		foreach ($opt_arr as $opt_val => $opt2){

				echo "<option value=\"{$opt_val}\">{$opt2[0]['value']}/{$opt2[1]['value']}</option>";

		}

	else if(strcmp($sel_name, "quantity")==0)

		foreach ($opt_arr[options] as $opt_val => $opt_text)

			echo "<option value=\"{$opt_val}\">{$opt_text['num']}</option>";

	echo "</select>";

}

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now