Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Displaying Default Images When There's No Photo Displayed on Bootstrap Carousel

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 636
    Answer it

    Hi there, I am having a problem here. Hope you can help me solve it.

     

    Scope: I have this slider which display pictures from my SQL which status is 1. It does display those pictures, but when there's no picture with 1 status, it doesn't want to display the default picture named "image.jpg"

     

    Here's the code:

    <div class="card-body">
    	<div id="SS" class="carousel slide" data-ride="carousel">
    		<ul class="carousel-indicators">
    			<li data-target="#SS" data-slide-to="0" class="active"></li>
    			<li data-target="#SS" data-slide-to="1"></li>
    			<li data-target="#SS" data-slide-to="2"></li>
    		</ul>
    	<div class="carousel-inner">
    		<?php
    			$no=1;
    			$default=$this->db->get_where("penyaluran", array("status" => "1"))->result();
    			foreach ($default as $pict)
    			{										
    				if (!empty($pict->status == "1"))
    				{
    					$g=$pict->foto_dokumentasi;
    					$n=$pict->nama_penyaluran;
    				}
    				else
    				{
    					$g='image.jpg';
    					$n='';
    					$status = 'active';
    				}
    				if ($no == 1)
    				{
    					$status = 'active';
    				}
    				else
    				{
    					$status = "";
    				}
    		 ?>
    		<div class="carousel-item <?php echo $status; ?>">
    			<img src="<?php echo base_url('uploads/'.$g); ?>" alt="" style="max-height: 300px; width: 1200px; margin-left: auto; margin-right: auto;">
    			<div class="carousel-caption">
    				<h3><?php echo $n; ?></h3> 
    			</div>
    		</div>
    		<a class="carousel-control-prev" href="#SS" data-slide="prev">
    			<span class="carousel-control-prev-icon bg-dark"></span>
    		</a>
    		<a class="carousel-control-next" href="#SS" data-slide="next">
    			<span class="carousel-control-next-icon bg-dark"></span>
    		</a>
    		<?php
    				$no++;
    			} 
    		?>
    		</div>
    	</div>
    </div>

    I am really clueless here. Whether my if statement is wrong or the foreach function. Did I miss something?

    Thanks in advance.

 0 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: