You are here: Re: dynamic drop-down list in array « PHP Programming Language « IT news, forums, messages
Re: dynamic drop-down list in array

Posted by Joe Estock on 04/12/05 16:29

Jonny Tango wrote:
> 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:
> 'com_courses.title'
>
>
>
> array (
> "coursetitle",
> "Course Title:",
> $EXTRA_SELECTLIST,
>
> array ("Report Writing", "Recruitment & Selection", "Presentation
> Skills", "Essential Telephone Skills", "Time Managememt", "Customer
> Care", "Other"),
> 0
> ),

$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.
>
>
>
> 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.

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.

>
> Thanks!!
>
> Jonny

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
time.

Joe Estock

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация