troubleshooting Question

PHP Contents of select statement stored in Array and used in Dropdown Menu

Avatar of stkoontz
stkoontzFlag for United States of America asked on
5 Comments1 Solution71 ViewsLast Modified:
I'd like to store the output of an SQL select statement into an array, then use that array to populate a dropdown menu.  

I'm using $result = $sth->fetchAll(); to store the contents of 2 fields into the array. Which comes out looking like this...

    [0] => Array
            [id_event_group] => uh
            [0] => uh
            [event_group_desc] => Urban Hope
            [1] => Urban Hope

    [1] => Array
            [id_event_group] => mo
            [0] => mo
            [event_group_desc] => Momentum
            [1] => Momentum


When I use the following code to create the dropdown, I just get 'array' 'array' as the options.

echo '<select name="event groups">';
echo '<option value="">Select...</option>';
foreach ($my_array as $k => $v) {
	echo '<option value="' . $k . '">' . $v . '</option>';
echo '</select>';

If it helps, here's a link to the page.

Thanks in advance for giving me a hand.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros