Reputation: 13
I have a problem. Why is the image in my code not displaying?
Here is my code:
<div class="panel-body">
<!-- start grids_of_3 -->
<?php
$query=$this->db->get('produk');
foreach($query->result_array() as $c) {
?>
<div class="grids_of_3">
<div class="grid1_of_3">
<a href="details.php">
<img src="<?php echo base_url('assets/uploads/$gambar')?>" alt=""/> **-> i think error in this**
<h3><?php echo $c['nama']?></h3>
<span ><?php echo $c['harga']?></span>
</a>
</div>
</div>
<?php } ?>
</div>
</div>
Can anyone solve my problem?
Upvotes: 0
Views: 1121
Reputation: 7111
Why is the image in my code not displaying?
You should check differences between single and double quotes in PHP.
Note: Unlike the double-quoted and heredoc syntaxes, variables and escape sequences for special characters will not be expanded when they occur in single quoted strings.
Make it like:
<img src="<?php echo base_url('assets/uploads/' . $gambar)?>" alt=""/>
or
<img src='<?php echo base_url("assets/uploads/$gambar")?>' alt=""/>
Upvotes: 1