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条)

报告相同问题?

悬赏问题

  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测