0

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?

3
  • What's the result of debugging? Are there any errors? Commented May 8, 2016 at 2:14
  • What's in $gambar ? Commented May 8, 2016 at 2:16
  • no error , just image cannot display , $gambar mean variabel for display image. Commented May 8, 2016 at 2:22

1 Answer 1

1

Why is the image in my code not displaying?


You should check differences between single and double quotes in PHP.

Docs says:

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=""/>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.