My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

Displaying Default Image in Bootstrap 4 Carousel using Code Igniter 3

Rangga Adi Pratama's photo
Rangga Adi Pratama
·Sep 26, 2019

Hello, I am having a problem with my slideshow. This slideshow displays pictures from my database which the picture has "1" status on it. The problem is when there's no picture with "1" status, nothing happened. Like this. See Dokumentasi Penyaluran.

Untitled.png

It should display the default image yet somehow it won't fetch it. Here's my code script.

<div class="carousel-inner">
    <?php
        $no=1;
        $default=$this->db->get_where("penyaluran", array("status" => "1"))->result();
        $g='image.jpg';
        $n='';
        foreach($default as $pict)
        {
            if ($g=$pict->foto_dokumentasi)
                {
                    $n=$pict->nama_penyaluran;
                }
            else
                {
                    $g='image.jpg';
                    $n= '';
                }
            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>
     <?php
            $no++;
        }
    ?>
    <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>
</div>

Did I miss something here? And, btw, I need someone to talk with as I am still new here. Thank you.