Kimpoy
Kimpoy

Reputation: 73

How can I display images in carousel using Codeigniter

I am using CI_3 and successfully inserted images to database and in directory but I can't get the image to display on carousel. How should I properly get the image to display it on a carousel?

(EDITED)

I have this on my Model:

function carousel(){
    $this->db->select('*');
    $this->db->where('status = 1');
    $query = $this->db->get('image');
    return $query->result_array();
    
}

Controller:

public function index()
{
    $data['content'] = $this->Home_model->getRows();
    $data['title'] = 'Products List';

    // Load the list page view
    $this->load->view('template/header');
    $this->load->view('template/topBarNav');
    $image = new Home_model;
    $data['images'] = $image->carousel();
    $this->load->view('pages/home', $data);
    $this->load->view('template/footer');
}

and display it on view like this:

      <div class="carousel-inner">
      <?php foreach ($images as $row) : ?>
        <div class="carousel-item card">
          <div class="parent d-flex justify-content-center">
            <img id="carousel_image" src="<?php echo base_url('uploads1/'.$row['upload_path']) ; ?>" class="img-responsive">
            <div class="carousel-caption">
              <h3><?php echo stripslashes(html_entity_decode($row['description'])); ?></h3>
            </div>
          </div>
        </div>
        <?php endforeach; ?>

But it doesn't display any images. I only get the folder path of the image and not the actual image.

Every uploaded image will create a folder according to their id, therefore every image are inside the generated folders inside uploads1 where I set the upload path for the images.

Upvotes: 0

Views: 315

Answers (1)

user17087887
user17087887

Reputation:

Your carousel is not working because your are set every item active that's the issue in this only first item was active only other are automatically active by your carousel .

You can try with removing active in loop make it first active only using condtions

<div class="carousel-inner">
    <?php foreach ($images as $i => $row) : ?>
      <div class="carousel-item card">
        <div class="parent d-flex justify-content-center">
          <img src="<?php echo base_url().'tourism/uploads1/'.$row['upload_path'] ?>" class="img-responsive">
          <div class="carousel-caption">
            <h3><?php echo stripslashes(html_entity_decode($row['description'])); ?></h3>
          </div>
        </div>
      </div>
    <?php endforeach; ?>

Upvotes: 1

Related Questions