在“选择"框中显示Mysql表字段值 [英] Display Mysql table field values in Select box

查看:86
本文介绍了在“选择"框中显示Mysql表字段值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在selectbox中显示Mysql表Filed值.我尝试显示以下代码. 但是它通常在回显功能中而不是在选择框中显示指定的字段值.我不知道我在哪里错.

I want to display the Mysql table Filed values in selectbox. I tried the following code to display. But it normally display the specified field values in echo function and not in select box. I don't know where I mistake.

 $con = mysql_connect("localhost","root","root");
 $db = mysql_select_db("Time_sheet",$con);
 $get=mysql_query("SELECT Emp_id FROM Employee");
 while($row = mysql_fetch_assoc($get))
{
echo ($row['Emp_id']."<br/>");
}

<html>
<body>
<form>
 <select> 
<option value = "<?php echo($row['Emp_id'])?>" ><?php echo($row['Emp_id']) ?></option>
</select>
</form>
</body>
</html>

此外,字段值必须以升序显示.怎么实现..

Also the field values must be display in ascending order. How to achieve..

推荐答案

<?php
$con = mysql_connect("localhost","root","root");
 $db = mysql_select_db("Time_sheet",$con);
 $get=mysql_query("SELECT Emp_id FROM Employee ORDER BY Emp_id ASC");
$option = '';
 while($row = mysql_fetch_assoc($get))
{
  $option .= '<option value = "'.$row['Emp_id'].'">'.$row['Emp_id'].'</option>';
}
?>
<html>
<body>
<form>
 <select> 
<?php echo $option; ?>
</select>
</form>
</body>
</html>

PS:在旁注中,请停止使用mysql_*功能.看看 线程的原因.

PS : On a sidenote, please stop using mysql_* functions. Take a look at this thread for the reasons.

这篇关于在“选择"框中显示Mysql表字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆