图片滑杆无法正常使用no_image [英] image slider is not working properly for no_image

查看:122
本文介绍了图片滑杆无法正常使用no_image的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个图像滑块,显示用户上传的图像.每个用户必须上传至少1张图片,最多上传4张图片.上载图片1是强制性的.其余未上传的用户另存为no_image.jpg文件.

I have image slider showing images which user uploaded. Every user has to uploaded at least 1 image and upto 4 as his interest. Uploading image 1 is compulsory. Rest which user didn't upload save as no_image.jpg file.

如果某人上传了1张图片,它将重复image1 2次.它工作正常,并且显示方式还可以.问题是,如果某人上传2或3张图片,它会重复某些图片2次.有点奇怪

If someone upload 1 image, it repeats image1 2 times. it works fine and the way it's showing is ok. Problem is if someone upload 2 or 3 image, it repeats some images 2 times. It's bit odd.

我不太了解编码.请有人帮助我解决此问题并使其完美工作.非常感谢您的帮助.

I don't know much about coding. Please someone help me to solve this issue and work this perfectly. Your help is highly appreciated.

image1代码未正确显示在此处.我不知道问题.它只是显示image1.没有if循环在那里.

Edited: image1 code is not displaying in here properly. I don't know issue. it is just shows image1. No if loop there.

<div class="product" >
<div class="thumbnail"><img src="<?php echo site_url(); ?>assets/images/adsimages/<?php
                                        $a = 'no_image.jpg';
                                        $b = $post['image2'];
                                        $c = $post['image3'];
                                        $d = $post['image4'];

                                        if ($b != $a) {
                                            echo $post['image2'];
                                        } elseif ($c != $a){
                                            echo $post['image3'];
                                        }elseif ($d != $a){
                                            echo $post['image4'];
                                        }else echo $post['image1']
                                        ?>" ></div>
</div>
<div class="product" >
<div class="thumbnail"><img src="<?php echo site_url(); ?>assets/images/adsimages/<?php
                                        $a = 'no_image.jpg';

                                        $c = $post['image3'];
                                        $d = $post['image4'];

                                        if ($c != $a){
                                            echo $post['image3'];
                                        }elseif ($d != $a){
                                            echo $post['image4'];
                                        }else echo $post['image1']
                                        ?>" ></div>
 </div>
 <div class="product" >
 <div class="thumbnail"><img src="<?php echo site_url(); ?>assets/images/adsimages/<?php
                                        $a = 'no_image.jpg';
                                        $d = $post['image4'];
                                            if ($d != $a){
                                            echo $post['image4'];
                                        }else echo $post['image1']
                                        ?>"></div>
                                </div>

推荐答案

您可以使用foreach显示日期,并防止自己重复代码.对于您的问题,您可以取一个空的array并在每个iteration上填充它,然后检查是否存在重复值,如果不是,则显示图像,如果是,则不显示图像.

You can use foreach to show the date and prevent yourself from repeating the code. For your problem, you can take an empty array and fill it on every iteration and check if there is a duplicate value, if not then show the image, if yes, then don't.

我为您的代码写了一个可能的解决方案,注释本身在代码中提到.看看是否对您有帮助.

I've written a possible solution for your code, comments are mentioned in the code itself. See if it helps you.

<?php 
    $imageArr = array(); // make an empty array

    foreach($post as $key => $singleImage){ // loop all the images 

        // if( !in_array($singleImage, $imageArr) ){ // check if current value already exists in array ie no_image 
        if( $key != 'id' && $singleImage != 'no_image.jpg' ) ){ // check if key is not id and its value is not no_image.jpg

            // $imageArr[] = $singleImage; // push the current value in array
?>
            <!-- Your view code here -->
            <div class="product" >
                <div class="thumbnail">
                    <img src="<?php echo site_url(); ?>assets/images/adsimages/$singleImage; ?>" /> 
                </div>
            </div>
<?php 
        }
    } 
?>

这篇关于图片滑杆无法正常使用no_image的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆