0

Image path is getting stored in the database and file is getting uploaded in the upload path but the image is not displaying in the tabular format. Here is the code for the view:

<tbody>
    <?php 
      $query = $this->db->query("SELECT * FROM banner_mgmt LIMIT 1");
      // $url = base_url().
      foreach ($query->result() as $row)
      {
        echo "<tr>";
        echo "<td>$row->id</td>";
        echo "<td>$row->banner_name</td>";
        echo "<td>".'<img src="base_url().$row->banner_image" style="height:150px; width:150px;" alt="not found">'."</td>";
        echo "<td>$row->banner_image</td>";
        echo "</tr>";
      }
    ?>
</tbody>

1 Answers1

2

Assuming that base_url().$row->banner_image does actually result in a correct path/image name...

You need to check your string concatenation.

What you have... (overly complicated)

echo "<td>".'<img src="base_url().$row->banner_image" style="height:150px; width:150px;" alt="not found">'."</td>";

What you should have...

echo '<td><img src ="'.base_url().$row->banner_image.'" style="height:150px; width:150px;" alt="not found"></td>';

You need to think about how you want the string to turn out, which helps you determine when and where to use ', " and . properly.

Here I am wrapping the string using ' (single quotes), which allows me to use " (double quotes) in the HTML properties without much effort.

Read up on how to use base_url() in the Codeigniter user guide...

So you could have

echo '<td><img src ="'.base_url($row->banner_image).'" style="height:150px; width:150px;" alt="not found"></td>';

You could even use " (double quotes) which evaluate php but you will need to escape any 'internal' double quotes you want to display.

echo "<td><img src =\"base_url($row->banner_image)\" style=\"height:150px; width:150px;\" alt=\"not found\"></td>";

So, you need to read the answer at What is the difference between single-quoted and double-quoted strings in PHP?

TimBrownlaw
  • 5,457
  • 3
  • 24
  • 28