Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从静态下拉列表中选择的数据库数据_Php_Mysql_Html - Fatal编程技术网

Php 从静态下拉列表中选择的数据库数据

Php 从静态下拉列表中选择的数据库数据,php,mysql,html,Php,Mysql,Html,所以我有这个: <select name="study_year"> <option>Year I</option> <option>Year II</option> <option>Year III</option> </select> 经典但丑陋的方法是: <select name="study_year"> <option <?php echo $selected['

所以我有这个:

<select name="study_year">
<option>Year I</option>
<option>Year II</option>
<option>Year III</option>
</select> 

经典但丑陋的方法是:

<select name="study_year">
<option <?php echo $selected['Year I'];?>>Year I</option>
<option<?php echo $selected['Year II'];?>>Year II</option>
<option<?php echo $selected['Year III'];?>>Year III</option>
</select> 

>第二年
假设“$list\u study”查询返回一个类似“Year I”的值 可以在“选择”对话框中的所有选项上添加此条件

<?php if($list_study == "Year I"){echo"selected";}?>


例如:

<select name="study_year">
<option <?php if($list_study == "Year I"){echo"selected";}?> >Year I</option>
<option <?php if($list_study == "Year II"){echo"selected";}?> >Year II</option>
<option <?php if($list_study == "Year III"){echo"selected";}?> >Year III</option>
</select> 

>第二年

我不能让它工作…你是说我在主要帖子上写的东西?该查询的结果是ID_stud=20,例如您编写的“第一年”是一个可接受的开始。你仍然需要从行中获取年份,并将其放入$year中我算出了,但我做的有点不同,提示用thx
<?php if($list_study == "Year I"){echo"selected";}?>

<select name="study_year">
<option <?php if($list_study == "Year I"){echo"selected";}?> >Year I</option>
<option <?php if($list_study == "Year II"){echo"selected";}?> >Year II</option>
<option <?php if($list_study == "Year III"){echo"selected";}?> >Year III</option>
</select>