How to retrieve imploded images path in database to view in code igniter

落花浮王杯 提交于 2019-12-02 08:45:39

You should try something like this

<?php foreach ($products as $p): ?>
  <?php 
      // explode images into a variable/array
      $images=explode('|',$p['picture']);
   ?>
  <tr>
      <td><?php echo $p['id']; ?></td>
      <td><?php echo $p['product_name']; ?></td>
      <td><?php echo $p['product_price']; ?></td>
      <td><?php echo $p['produce_description']; ?></td>
      <!-- <td><?php echo $p['picture']; ?> </td> -->
      <td><img src="<?php echo base_url('uploads/images/').$images[0];?>" /> </td>
      <td>
          <a href="<?php echo site_url('products/view/'.$p['id']); ?>">View</a> |
          <a href="<?php echo site_url('products/edit/'.$p['id']); ?>">Edit</a> |
          <a href="<?php echo site_url('products/delete/'.$p['id']); ?>" onClick="return confirm('Are you sure you want to delete?')">Delete</a>
      </td>
  </tr>

Edit

I will give you an example from a code in production at this link

<div class="aa-properties-details-img" style="margin-bottom: 25px;">
<?php
    $property[0]['images']=explode(',',$property[0]['img']);
    if(count($property[0]['images'])>0){
       for($i=0;$i<count($property[0]['images']);$i++)
       { ?>
        <img src="<?php echo  base_url().'img/'.$property[0]['images'][$i]?>" alt="img">
       <?php }
       }else{
       ?>
        <img src="<?php echo base_url().'img/no-image.jpg'?>" alt="img">
       <?php
     }
?>
</div>

Try this:

<?php foreach ($products as $p): ?>
  <tr>
      <td><?php echo $p['id']; ?></td>
      <td><?php echo $p['product_name']; ?></td>
      <td><?php echo $p['product_price']; ?></td>
      <td><?php echo $p['produce_description']; ?></td>
      <td>
       <?php  $images=explode('|',$p['picture']); 
          foreach($images as $image) {
       ?>
      <img src="<?php echo base_url('uploads/images/').$image; ?>" width="50" height="50" />
      <?php } ?>
      </td>
      <td>
          <a href="<?php echo site_url('products/view/'.$p['id']); ?>">View</a> |
          <a href="<?php echo site_url('products/edit/'.$p['id']); ?>">Edit</a> |
          <a href="<?php echo site_url('products/delete/'.$p['id']); ?>" onClick="return confirm('Are you sure you want to delete?')">Delete</a>
      </td>
  </tr>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!