donglu1971 2019-05-28 18:14
浏览 234
已采纳

从HTMl表单的动态选择选项中删除重复数据

In my website's database, there are a lot of posts inserted with the date. I am making a post shorting system where a user selects a year from the dynamic dropdown and after pressing the submit button only that year's post will be visible on the website. Everything is going good but on the dynamic dropdown, a year is showing multiple time.

For example, There are 3 posts in my database which date is 2/2/2019 , 21/2/2019 , 22/3/2019. In my dynamic dropdown there I find 2019 3 times, but I need to show 2019 only one time.

I have tried some jQuery and JavaScript code but it did not work.

My code :

<?php        
    $query = "SELECT year(date) FROM `press_release` WHERE del_status=0";
    $year = $conn->query($query);
?>

<form class="form-inline title" action="press_new.php" method="post">
    <div class="form-group">
        <label for="" style="color:#EB2227">Search by year</label>
        <select name="year">
            <option value="0">Please Select</option>

            <?php while($row = mysqli_fetch_array($year)){ ?>
                <option value="<?php echo($row['year(date)'])?>">
                    <?php echo($row['year(date)']) ?>
                </option>
            <?php } ?>
        </select>
        <button type="submit" name="submit" class="btn btn-default" style="background-color:#EB2227">Submit</button>
    </div>
</form>
  • 写回答

2条回答 默认 最新

  • dqw70970 2019-05-28 18:18
    关注

    Have you tried DISTINCT ?

    $query = "SELECT DISTINCT year(date) FROM `press_release` WHERE del_status=0";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划