You are here: Re: PHP edit form for MySQL database using <Select> fields « PHP Programming Language « IT news, forums, messages
Re: PHP edit form for MySQL database using <Select> fields

Posted by Roy W. Andersen on 06/19/06 00:41

ghadley_00@yahoo.com wrote:
[snip]
> I am having trouble figuring out a way to have
> the appropriate option in the <Select> fields chosen to reflect the
> data already in the database. Does anyone have any suggestions on how I
> can accomplish this?

Sure.

$data = mysql_fetch_array(mysql_query('SELECT fieldname FROM table WHERE
id='.$theId));

echo '
<select name="mylist">
<option value="option1"'; if ($data['fieldname'] == 'option1') { echo '
selected="selected"'; } echo '>Option 1</option>
<option value="option2"'; if ($data['fieldname'] == 'option2') { echo '
selected="selected"'; } echo '>Option 2</option>
';
....etc...
echo '</select>';

This is how I do these things atleast. The point is to check if the
option is the one in the db, and if it is, add selected="selected" (or
just selected if you're not using xhtml).


Roy W. Andersen
--
ra at broadpark dot no / http://roy.skyggenesdal.org/

"Hey! What kind of party is this? There's no booze
and only one hooker!" - Bender, Futurama

 

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

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