Mailinglisten-Archive |
> > Hallo liebe Liste,
> > ich habe ein select-feld mit Einträgen aus einer DB gefüllt.
> > Der erste Eintrag wird immer 'selected'.
> > Wie kann ich erreichen, daß auch andere ausgewählte Einträge im Feld
> > stehen bleiben?
> > Ich habe schon div. if/else Konstrukte probiert - bin aber zu keiner
> > Lösung gelangt.
>
> <?
>
> mysql_pconnect("host","user","pass");
> mysql_select_db("datenbank");
>
> $pleaseSelectItem = 56;
>
> $result = mysql_query("SELECT id,name FROM tabelle ORDER BY name");
>
> ?><select name="foo"><?
>
> while($row = mysql_fetch_array($result)) {
> if($row["id"] == $pleaseSelectItem) {
> ?><option value="<?=$row["id"]?>" selected><?=$row["name"]?><?
> } else {
> ?><option value="<?=$row["id"]?>"><?=$row["name"]?><?
> }
> }
>
> ?></select><?
funktioniert leider auch nicht. So eine ähnliche Lösung hatte ich bereits.
Bei mir sieht es so aus:
$pleaseSelectItem = 2;
while ($row = mysql_fetch_array($sql_result)) {
if($row["auswahl_id"] == $pleaseSelectItem) {
$option_block .= "<option value=" .$row["auswahl_id"]."
selected >".$row["auswahl"]."</option>";
}else{
$option_block .= "<option value="
.$row["auswahl_id"].">".$row["auswahl"] ."</option>";
}
}
$option_block wird über:
<form action="top.php3" method="post" target="">
<select name="SEL_FELD" value=<? echo "$SEL_FELD"; ?>size="1">
<? echo "$option_block"; ?>
</select>
eingefügt.
Hast du noch andere Ideen. Ich komme leider alleine nicht weiter
Liebe Grüße
Frank
--
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net
--
GMX Tipp:
Machen Sie Ihr Hobby zu Geld bei unserem Partner 1&1!
http://profiseller.de/info/index.php3?ac=OM.PS.PS003K00596T0409a
php::bar PHP Wiki - Listenarchive