Php 通过链接在图像库上使用过滤器
首先,我的英语不是最好的,所以我会尽我所能解释我想做什么: 我的网站上有一个图像库,所有图像都存储在数据库中。每个图像都有一种类别,数据库中有一个包含所有类别的表 在图像库下方,我有一个导航,上面列出了所有类别:Php 通过链接在图像库上使用过滤器,php,html,filter,nav,Php,Html,Filter,Nav,首先,我的英语不是最好的,所以我会尽我所能解释我想做什么: 我的网站上有一个图像库,所有图像都存储在数据库中。每个图像都有一种类别,数据库中有一个包含所有类别的表 在图像库下方,我有一个导航,上面列出了所有类别: <nav class="cl-effect-5"> <a href="#"><span data-hover="All">All</span></a>
<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>
我希望用户点击其中一个类别,画廊将只显示有该类别的图片,但我不知道如何做,我不是很熟练的编码
谢谢;) 在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 ;