Image Slider Is Not Working Properly For No_image
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 did
Solution 1:
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 arrayforeach($postas$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 --><divclass="product" ><divclass="thumbnail"><imgsrc="<?phpecho site_url(); ?>assets/images/adsimages/$singleImage; ?>" /></div></div><?php
}
}
?>
Post a Comment for "Image Slider Is Not Working Properly For No_image"