I get the following error : Cannot access offset of type string on string
On this line
<img class="card-img-top" src="<?php echo base_url('uploads/products_images/'.$row['prod_image'] ); ?>" alt="">
What can be the issue with the above line
This is the code...
<h2>PRODUCTS</h2>
<!-- Cart basket -->
<div class="cart-view">
<a href="<?php echo base_url('cart'); ?>" title="View Cart"><i class="icart"></i> (<?php echo ($this->cart->total_items() > 0)?$this->cart->total_items().' Items':'Empty'; ?>)</a>
</div>
<!-- List all products -->
<div class="row col-lg-12">
<?php if(!empty($products)){
foreach($products as $row){ ?>
<div class="card col-lg-3">
<img class="card-img-top" src="<?php echo base_url('uploads/products_images/'.$row['prod_image'] ); ?>" alt="">
<div class="card-body">
<h5 class="card-title"><?php echo $row["name"]; ?></h5>
<h6 class="card-subtitle mb-2 text-muted">Price: <?php echo 'Ksh'.$row["price"].' Ksh'; ?></h6>
<p class="card-text"><?php echo $row["description"]; ?></p>
<a href="<?php echo base_url('products/addToCart/'.$row['id']); ?>" class="btn btn-primary">Add to Cart</a>
</div>
</div>
<?php } }else{ ?>
<p>Product(s) not found...</p>
<?php } ?>
</div>
Be sure $row
is an array,is not string.Check $products
variable in controller by debugging:
dd($products);