在处理数据和填充方面需要帮助:
我正在创建Employee数据库,有两个页面: 1.添加员工 2.修改员工
添加员工,获取EMP名称,EMP ID,经理名称(下拉列表),位置(选择它们的无线电选项)等输入 所有这些输入都写入数据库。
员工ID <div class="fb-input-number">
<input id="item12_number_1" name="emp_number" min="0" max="999999999" autocomplete="off" data-hint="" required="" step="1" type="number">
</div>
</div>
<select id="item13_select_1" name="Manager" data-hint="">
<option id="item13_0_option" value="Tom" >
TOM
</option>
<option id="item13_1_option" value="Harry" selected="selected">
HARRY
</option>
</select>
<label id="item16_0_label">
<input id="item16_0_radio" checked="checked" name="radio_location" data-hint="" value="IND" type="radio">
<span id="item16_0_span" class="fb-fieldlabel">
INDIA
</span>
</label>
<label id="item16_1_label">
<input id="item16_1_radio" name="radio_location" value="EMEA" type="radio">
<span id="item16_1_span" class="fb-fieldlabel">
EMEA
</span>
</label>
在“修改员工”页面中,基于emplyee ID,我想要使用db到html页面的值来呈现页面。 我正在使用类似的页面来修改条目。我可以按值= $ EMPID显示文本字段。如何为下拉列表和复选框执行相同操作?
员工ID <div class="fb-input-number">
<input id="item12_number_1" name="emp_number" min="0" max="999999999" autocomplete="off" data-hint="" required="" step="1" type="number" value="11222">
</div>
</div>
<select id="item13_select_1" name="Manager" data-hint="">
<option id="item13_0_option" value="Tom" >
TOM
</option>
<option id="item13_1_option" value="Harry" selected="selected">
HARRY
</option>
</select>
<label id="item16_0_label">
<input id="item16_0_radio" name="radio_location" data-hint="" value="IND" type="radio">
<span id="item16_0_span" class="fb-fieldlabel">
INDIA
</span>
</label>
<label id="item16_1_label">
<input id="item16_1_radio" name="radio_location" value="EMEA" type="radio" checked="checked">
<span id="item16_1_span" class="fb-fieldlabel">
EMEA
</span>
</label>
你能帮我吗?
基本上我想出了修改页面,它将从数据库中检索数据并以HTML格式显示。下面的代码没有帮助显示所选的值:
<?php
mysql_connect($SERVER_IP, $USERNAME, $PWD) or die(mysql_error());
mysql_select_db($DBNAME) or die(mysql_error());
$result=mysql_query("SELECT * from `Data` where Emp_ID = $MyEmpID ");
$info = mysql_fetch_array( $result );
$Location=$info['Location'];
?>
<html>
<body>
<div class="fb-dropdown">
<select id="item13_select_1" name="location" data-hint="">
<option id="item13_0_option" value="BLR" <? if ($Location=="BLR") echo "selected"; ?> >
Bangalore
</option>
<option id="item13_1_option" value="EMEA" <? if ($Location=="EMEA") echo "selected"; ?> >
EMEA
</option>
</select>
</div>
</body>
</html>
我该如何解决?
答案 0 :(得分:0)
当您的脚本呈现选择列表时,如果其值与DB值匹配,则必须检查每个选项。如果是,请将所选属性添加到该选项。
答案 1 :(得分:0)
以下解决了问题:
<?php
mysql_connect($SERVER_IP, $USERNAME, $PWD) or die(mysql_error());
mysql_select_db($DBNAME) or die(mysql_error());
$result=mysql_query("SELECT * from `Data` where Emp_ID = $MyEmpID ");
$info = mysql_fetch_array( $result );
$Location=$info['Location'];
$locations[0]="BLR";
$locations[1]="Provo";
$locations[2]="EMEA";
$locations[3]="APAC";
?>
<html>
<body>
<div class="fb-dropdown">
echo "
<select name='location'>";
for ($i=0; $i<=4; $i++)
{
if($Location == $locations[$i]){
echo "<option selected value='$locations[$i]'>$locations[$i]</option>";
}else {
echo "<option value='$locations[$i]'>$locations[$i]</option>";
}
}
echo" </select>
</div>
</body>
</html>