hello,
i have a function, that contains an array.
this function puts out a complete "select" tag with options and makes ONE option "selected".. getting from Session.
here some code:
function ShowTheUserDataLiefergebiet($GetThis) {
$data = array(
'1' => "Bitte Auswählen",
'2' => "Town1",
'3' => "Town2",
'4' => "Town3",
'5' => "Town4"
);
$output = "
<select name=\"Liefergebiet\" id=\"Liefergebiet\">";
for($i = 1;$i <= count($data); $i++) {
$selected = "";
if(Session::get("Liefergebiet") == $i) {
$selected = "selected=\"selected\"";
}
$output .= "<option ".$selected." value=\"".$i."\" >".$data[$i]."</option>";
}
$output .= "
</select>
";
if(isset($GetThis)) {
return $data[$GetThis];
} else {
return $output;
}
}
maybe its not that clear at the first view. i use this funtion in 2 different ways.
when i call the function like this:
$ShowTheUserDataLiefergebiet(2)
then i get the Value Name.. so here it's "Town 1".
in the "session data", there is "Liefergebiet" a number, because i want to make selected.. and because the value in the session is a number, i use this fuction to output the Name Value and not the number..
<% control ShowTheUserData %>
<p>$Name</p>
<p>$Email</p>
<p>....</p>
<p>$Top.ShowTheUserDataLiefergebiet(2)</p>
<% end_control %>
sooo... to output the $Liefergebiet value from the session, i do "$Liefergebiet" in ss-file.
but thing like THIS does not work.. :(
<p>$Top.ShowTheUserDataLiefergebiet($Liefergebiet)</p>
but this works:
<p>$Top.ShowTheUserDataLiefergebiet(2)</p>
soo, at first i did this.. the following code works:
<p>Liefergebiet:
<% if Liefergebiet = 1 %>
$Top.ShowTheUserDataLiefergebiet(1)
<% end_if %>
<% if Liefergebiet = 2 %>
$Top.ShowTheUserDataLiefergebiet(2)
<% end_if %>
<% if Liefergebiet = 3 %>
$Top.ShowTheUserDataLiefergebiet(3)
<% end_if %>
<% if Liefergebiet = 4 %>
$Top.ShowTheUserDataLiefergebiet(4)
<% end_if %>
<% if Liefergebiet = 5 %>
$Top.ShowTheUserDataLiefergebiet(5)
<% end_if %>
</p>
but isn't there a better way?
help please :D