我正在创建一个下拉按钮,该按钮可让您从选项列表中选择年份,以便对数据表进行排序。代码(转载如下)不断重复去年,我似乎无法弄清楚为什么这样做。我正在使用PHP从MySql数据库中提取数据。
<div class="dropdown">
<button onclick="myFunction()" class="dropbtn">Select Year</button>
<div id="myDropdown" class="dropdown-content">
<?php
$year = array();
while($subject = mysqli_fetch_assoc($subject_set)) {
$i=0;
$exists = 0;
$n = count($year);
while($i < $n){
if ($subject['year'] == $year[$i]){
$exists = 1;
}
$i++;
}
if($exists == 0){
$year[$n] = $subject['year'];
echo "<a href=\"index.php?year={$subject['year']}\"> {$subject['year']} </a>";
}
}
$subject_set = find_all_subjects();
?>
</div>
</div>