Reply to Re: <select> value ?

Your name:

Reply:


Posted by Geoff Berrow on 10/16/06 08:57

Message-ID: <45333112$0$1117$ba620e4c@news.skynet.be> from = poster =
contained the following:

>I have also a script which alows the user to edit their choises.
>The problem is that I don't know how to set the value from the database into
>the select thingy.

I usually use a function to create select boxes, having previously
stored values in an array (either hard coded or taken from a db).

//$array Array of values for the select box e.g.
//$array=array("01"=>"1","02"=>"2","03"=>"3", ...)
//or could come from db
//$name is the name of the select box
//$chosen is current selection taken from $_POST ed value or db

function select($array,$name,$chosen){
$select_box="<select name='$name'>\n";
foreach($array as $key=>$value){
$selected=($key==$chosen)?" selected" : "";
$select_box.=" <option
value='$key'$selected>$value</option>\n";
}
$select_box.="</select>\n";
return $select_box;
}

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/

[Back to original 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

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