我想在生日字段中填充php中的选择框多年.从查询中设置变量$ year,并且必须在我的选择框中选择特定年份.到目前为止的代码就是这个,它只填充了几年,但它没有选择存储在mysql db中的年份,有谁知道为什么?谢谢
$year = $row['year']; // this comes from a query that is stored in the db
<select name="year"><?
for ($x = 1920; $x < date('Y'); $x++) {
?><option value=<? echo $x; if ($x == $year) {echo 'selected="selected"';}?>><? echo $x;?></option><?
}?>
</select>
Run Code Online (Sandbox Code Playgroud)