【问题标题】:Using filters on image gallery through links通过链接在图片库上使用过滤器
【发布时间】:2014-05-13 11:37:00
【问题描述】:

首先,我的英语不是最好的,所以我会尽力解释我要做什么:

我的网站上有一个图片库,所有图片都存储在数据库中。每张图片都有一个类别,数据库中有一个包含所有类别的表。

在图片库下方,我有这个导航,列出了所有类别:

<nav class="cl-effect-5">
                    <a href="#"><span data-hover="All">All</span></a>
                    <a href="#"><span data-hover="Black and White">Black and white</span></a>
                    <a href="#"><span data-hover="Panoramic">Panoramic</span></a>
                    <a href="#"><span data-hover="Nature">Nature</span></a>
                    <a href="#"><span data-hover="City">City</span></a>
                    <a href="#"><span data-hover="Others">Others</span></a>
                </nav>

我希望用户点击这些类别之一,画廊将只显示具有该类别的图片,但我不知道该怎么做,而且我的编码不是很熟练。

谢谢 ;)

【问题讨论】:

    标签: php html filter nav


    【解决方案1】:

    在 JS 文件中:

    $(document).ready(function() {
      $('.cl-effect-5 a span ').click(function() {
      var selected=$(this).attr('data-hover');
      $.get("query.php?selected="+selected, function(data){
      $('.result').html(data);
    
       });
     });
    });
    

    您应该在其中创建 query.php 文件以及您的查询和代码,并在其中返回结果

     $type = $_POST["selected"];
    
     $query="select * from table where type='".$type."'";
     $html="";
     while($row = mysqli_fetch_array($query)) {
       $html .= $row['image_link'];
      }
     echo $html ;
    

    【讨论】:

      猜你喜欢
      • 2017-10-08
      • 2018-06-12
      • 2016-09-29
      • 1970-01-01
      • 2017-02-10
      • 2015-05-01
      • 2020-03-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多