0

I am trying to display images on my web page, the content is getting fetched from my database, but the issue I'm facing is in displaying the image. please, can anyone guide me how should I display the image?

I mean to say the path what I should give

here 'image' is my column name and this is my view

        <?php 
            if( !empty($results) ) {

                foreach($results as $row) {?>
                <div class="col-sm-4">
                  <img src="<?php echo base_url('uploads/');$image?>" alt="">
                  <h3><?php echo $row->title; ?></h3>
                  <p><?php echo $row->content; ?></p>
                </div> 
               <?php 

               } ?>

            <?php }
        ?>
Pradeep
  • 9,667
  • 13
  • 27
  • 34
keerthi patil
  • 123
  • 2
  • 13

4 Answers4

2

Hope this will help you :

Use this : <img src="<?php echo base_url('uploads/'.$row->image);?>" alt="">

The whole code should be like this :

<?php 
            if( !empty($results) ) {

                foreach($results as $row) {?>
                <div class="col-sm-4">
                  <img src="<?php echo base_url('uploads/'.$row->image);?>" alt="">
                  <h3><?php echo $row->title; ?></h3>
                  <p><?php echo $row->content; ?></p>
                </div> 
               <?php 

               } ?>

            <?php }
        ?>
Pradeep
  • 9,667
  • 13
  • 27
  • 34
1

If $image is the column name(which contains image name) then Replace

<img src="<?php echo base_url('uploads/');$image?>" alt=""> 

with

 <img src="<?php echo base_url();?>uploads/<?php echo $row->image;?>" alt="">
Archana
  • 233
  • 1
  • 2
  • 7
0

If $image has image path then remove ';' and add '.' on echo base_url('uploads/');$image?> line

-1

You issue here is the following code;

<?php echo base_url('uploads/');$image?>

This is because you are not concatenating the string, rather, just saying it's variable name, so, use of the following will provide the output;

<?php echo base_url('uploads/') . $image' ?>

This replaces the semi-colon part way through for a period (.) which is the PHP concatenation operator

Obviously, there is the issue you are not setting $image, which would require (before usage) of;

$image = $row['image_column_name'];
// Or
$image = $row->img_column_name
Can O' Spam
  • 2,718
  • 4
  • 19
  • 45