PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Little Spy
Forum Commoner
Posts: 31 Joined: Thu Oct 10, 2002 8:18 pm
Contact:
Post
by Little Spy » Sat Nov 09, 2002 2:15 pm
$data['userlevel'] is the admin level of the user taken from the data base in the modify user form i have this snippet
Code: Select all
if ($dataї'userlevel'] == "0") {
<select size="1" name="member_modify_userlevel">
<option value="0" selected>0 - Normal User</option>
<option value="1">1 - SiteOP</option>
<option value="2">2 - SiteOp+</option>
<option value="3">3 - SuperOp</option>
</select>
}
elseif ($dataї'userlevel'] == "1") {
<select size="1" name="member_modify_userlevel">
<option value="0" selected>0 - Normal User</option>
<option value="1" selected>1 - SiteOP</option>
<option value="2">2 - SiteOp+</option>
<option value="3">3 - SuperOp</option>
</select>
}
elseif ($dataї'userlevel'] == "2") {
<select size="1" name="member_modify_userlevel">
<option value="0" selected>0 - Normal User</option>
<option value="1">1 - SiteOP</option>
<option value="2" selected>2 - SiteOp+</option>
<option value="3">3 - SuperOp</option>
</select>
}
elseif ($dataї'userlevel'] == "3") {
<select size="1" name="member_modify_userlevel">
<option value="0">0 - Normal User</option>
<option value="1">1 - SiteOP</option>
<option value="2">2 - SiteOp+</option>
<option value="3" selected>3 - SuperOp</option>
</select>
}
to make the userlevel they currently are be selected, i really hate to do it this way does anyone know a better way?
Takuma
Forum Regular
Posts: 931 Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:
Post
by Takuma » Sat Nov 09, 2002 2:18 pm
You couls use SWITCH instead of IF and also try printing out the <select> first.
phpScott
DevNet Resident
Posts: 1206 Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.
Post
by phpScott » Sat Nov 09, 2002 4:25 pm
Try this alternative. It's not as elegant as I would like but it will make updating your script a little easier.
Code: Select all
<?php
$select0="";
$select1="";
$select2="";
$select3="";
switch ($dataї'userlevel'])
{
case "0":
$select0="selected";
break;
case "1":
$select1="selected";
break;
case "2":
$select2="selected";
break;
case "3":
$select3="selected";
break;
}
$selectBox = " <select size='1' name='member_modify_userlevel'>";
$selectBox .=" <option value='0' $select0>0 - Normal User</option>";
$selectBox .=" <option value='1' $select1>1 - SiteOP</option>";
$selectBox .=" <option value='2' $select2>2 - SiteOp+</option>";
$selectBox .=" <option value='3' $select3>3 - SuperOp</option>";
$selectBox .=" </select>";
print $selectBox;
?>
phpScott
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sat Nov 09, 2002 8:19 pm
there are thousands of ways
Code: Select all
<select name="member_modify_userlevel"><?php
$desc = array(0=>'Normal User', 1=>'SiteOP', 2=>'SiteOp+', 3=>'SuperOp');
foreach($desc as $key=>$value)
echo '<option value="', $key, ($key==$dataї'userlevel']) ? '" selected="selected">':'">', $value, '</option>';
?></select>hmm....my phoenix/mozilla doesn't recognize the selected-property but IE does