Home > OS >  : Cannot access offset of type string on string
: Cannot access offset of type string on string

Time:11-10

I get the following error : Cannot access offset of type string on string

On this line

  <img  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 >
    <a href="<?php echo base_url('cart'); ?>" title="View Cart"><i ></i> (<?php echo ($this->cart->total_items() > 0)?$this->cart->total_items().' Items':'Empty'; ?>)</a>
</div>

<!-- List all products -->
<div >
    <?php if(!empty($products)){ 
        foreach($products as $row){ ?>
        <div >
            <img  src="<?php echo base_url('uploads/products_images/'.$row['prod_image'] ); ?>" alt="">
            <div >
                <h5 ><?php echo $row["name"]; ?></h5>
                <h6 >Price: <?php echo 'Ksh'.$row["price"].' Ksh'; ?></h6>
                <p ><?php echo $row["description"]; ?></p>
                <a href="<?php echo base_url('products/addToCart/'.$row['id']); ?>" >Add to Cart</a>
            </div>
        </div>
    <?php } }else{ ?>
        <p>Product(s) not found...</p>
    <?php } ?>
</div>

CodePudding user response:

Be sure $row is an array,is not string.Check $products variable in controller by debugging:

dd($products);
  • Related