简体   繁体   English

php 画廊中不显示带有空格的单词的结果

[英]Results in words with space don't show in php gallery

I'm creating a gallery in php, where it has a filter divided into categories.我正在 php 中创建一个画廊,其中有一个按类别划分的过滤器。 But when a word has a space it doesn't show the associated images.但是当一个词有一个空格时,它不会显示相关的图像。 I'm working on two tables, one that creates the categories and the other that is from the gallery.我正在处理两张表,一张创建类别,另一张来自画廊。

This is my code and the sql queries:这是我的代码和 sql 查询:

Querys:查询:

$sql = "selec categoria AS categoria_formatted from cat_lar";
$galerialar = $connect->query($sql);
$sql = "select foto,categoria_lar from galeria_lar,cat_lar  Where categoria_lar=categoria";
$galerialarconde = $connect->query($sql);

Code:代码:

<div class="popular page_section">
    <div class="container">
        <div class="row">
        <div align="center">
        <button class="filter-button" data-filter="all">All</button>
        <?php mysqli_data_seek($galerialar, 0);
        
        while( $galerialarc = $galerialar -> fetch_assoc()){ ?>
            <button class="filter-button" data-filter="<?php echo $galerialarc['categoria_formatted']?>"><?php echo $galerialarc['categoria_formatted']?></button>
        <?php } ?>
        </div>
        
        <br/>
        <?php 
        while( $galerialarc = $galerialarconde -> fetch_assoc()){ ?>
        <div class="gallery_product col-sm-3 col-xs-6 filter <?php echo $galerialarc['categoria_lar']?>">
            <a class="fancybox" rel="ligthbox" href="admin/galeria/uploads/<?php echo $galerialarc['foto']?>">
                <img class="img-responsive" alt="" src="admin/galeria/uploads/<?php echo $galerialarc['foto']?>" width="150px" />
            </a>
        </div>
        <?php }?>




        </div>
    </div>
</div>

SCRIPT:脚本:

<script>
$(document).ready(function(){

    $(".filter-button").click(function(){
        var value = $(this).attr('data-filter');
        
        if(value == "all")
        {
            $('.filter').show('1000');
        }
        else
        {
            $(".filter").not('.'+value).hide('3000');
            $('.filter').filter('.'+value).show('3000');
            
        }

        if ($(".filter-button").removeClass("active")) {
            $(this).removeClass("active");
        }
        $(this).addClass("active");
    });
});
/*  end gallery */

$(document).ready(function(){
    $(".fancybox").fancybox({
        openEffect: "none",
        closeEffect: "none"
    });
});
   
</script>

Can they help me?他们能帮我吗? Because I've already tried to put the words with "_" and replace and it remained the same因为我已经尝试用“_”来替换这些词并且它保持不变

As you suggest yourself, the image URLs can't contain whitespaces.正如您自己建议的那样,图像 URL 不能包含空格。 If you already tried to replace whitespaces with underscores ( _ ), remember to upload the image files with that name and replace the foto url in the database with the new images.如果您已经尝试用下划线 ( _ ) 替换空格,请记住上传具有该名称的图像文件,并将数据库中的照片 url 替换为新图像。

If it doesn't work, try to investigate where exactly the problem occurs.如果它不起作用,请尝试调查问题发生的确切位置。 Is the queries returning the right results (try to var_dump() the result and see if they are missing. If you think the problem happends in the HTML, try using your "inspect" feature in your browser and see if a source URL is provided for the image element and check if this URL really has an image.查询是否返回正确的结果(尝试 var_dump() 结果并查看它们是否丢失。如果您认为问题发生在 HTML 中,请尝试使用浏览器中的“检查”功能并查看是否提供了源 URL对于图像元素,检查这个 URL 是否真的有图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM