dynamic drop-down list in array

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Hello everyone.

Q. How do I create a dynamically-generated drop-down list for use in
an array.

I'm using PHP with a MySQL database (through phpMyAdmin)

My database table is called com_courses, and I want to pull the
distinct 'title' fields and have them appear as a drop down menu for
the user to select in a form.

Here is my array, with (at the moment) manually-entered 'titles'
(which I now need to be dynamically generated from my database field:

array (
     "Course Title:",          
     array ("Report Writing", "Recruitment & Selection", "Presentation
Skills", "Essential Telephone Skills", "Time Managememt", "Customer
Care", "Other"),

I am not an experienced programmer, but can play around with php to
customize programs. I've read up on arrays (I bought a "Programming
with PHP and MySQL" book, but it just stops short of this problem). I
can't figure this one out.

Is this enough info for you kind people to help me?
ANY real code would be soooooo helpful (so I could paste it in),
because, as I mentioned, I'm good at editing existing code rather than
creating code from scratch. But ANY help/guidance/funny comments would
be appreciated.



Re: dynamic drop-down list in array

Jonny Tango wrote:
Quoted text here. Click to load it

$myar = array
  'Option 1', 'Option 2', 'Option 3', 'Option 4',
  'Option 5', 'Option 6', 'Option 7', 'Option 8'

echo '<select name="myselect">';

for($i = 0; $i < count($myar); $i++)
  echo '<option value="'.$i.'">'.$myar[$i].'</option>';

echo '</select>';

This will generate a select list for you.
Quoted text here. Click to load it

You better learn to get good at creating code from scratch. Not
everthing will be pre-made for you. If that were the case, my job would
be conciderablly easier.

Quoted text here. Click to load it

You should study php more before you dive into something as complex as
this. Being able to splice code together and get it to work does not
count, you need some actual experience in writing code. You seem like
you have a fair understanding, therefore a few searches on google and I
think you will pick up on it in no time. Also, for any core function you
can go to http://www.php.net/function_name and get information about
that function (e.g., http://www.php.net/htmlspecialchars ).

One last note, do not cross-post into different newsgroups.
comp.lang.php is the appropriate newsgroup for your question 98% of the

Joe Estock

Site Timeline