duanbozhong9689 2014-10-15 22:24
浏览 47

过滤foreach的结果...... PHP

I currently have a list of items that are stored in a database that are retrieved and displayed using a foreach.

foreach($files as $file){
echo'<div class="col-lg-9" id="file-'.$file['id'].'">
        <div class="file-list-item first" id="">
            <img class="file-image" height="120px" width="180px" src="'.$file['image_url'].'" />
            <div class="file-text">
                <h3><strong>'.$file['name'].'</strong></h3>
                Submitted by: '.$file['submitter'].'<br/>
                Author: '.$file['author'].'<br />
                Category: '.ucfirst($file['subcategory']).'<br />
                Description: '.substr($file['description'],0,45).'...
            </div>
            <div class="download">
                <a target="_blank" href="'.$file['download_url'].'" class="btn-success btn btn-default">Download</a>
                <a href="'.baseurl.'/broken.php?id='.$file['id'].'" class="btn btn-default">Report as Broken</a><br /><br />';
                    if($file['is_broken']){
                        echo '<span class="broken"><i data-toggle="tooltip" data-placement="left" id="broken" title="This file has been reported as broken and is awaiting review." class="fa fa-warning fa-2x"></i></span>';
                    }


                echo '

            </div>
        </div>
    </div>';
};

What would be the best way to filter these results using a drop down menu? The value I wish to filter by is `$file['subcategory']

So, I wish for various categories to be displayed in a dropdown menu, and once the value of this is changed, I wish for the page to refresh and display only the results the user desires.

Many thanks.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 关于大棚监测的pcb板设计
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用
    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入