Search code examples
imagecodeigniterquotes

Can't get image out with appended numbering - CodeIgniter


its a silly question but I'm really bad in escaping quotes :/.

I'm using the table class to generate a table of products, and in that table each row has an image to be displayed for that product. The images are stored using their product_id as a name with an appended "_x" because there's more than one image per product, so an example of an image name is 193_1.

This is how I'm generating my rows for the table:

$table_row = array();
    foreach ($r->result() as $p)
    {
      $table_row = NULL;
      $table_row[] = "<img src='http://localhost/CI/photos/$p->product_id\"1\".jpg' height='150' width='150'/>";
      $table_row[] = $p->product_id;
      $table_row[] = $p->title;
      $table_row[] = $p->description;
      $table_row[] = $p->price;
      $table_row[] = $p->stock;

      $this->table->add_row($table_row);
    }

But the image won't show, even when I've escaped the '1'. I only want to display the first image as that is the main one, so that's why I've hard-coded the number. Could someone please help? I've tried multiple ways i.e.

"<img src='http://localhost/CI/photos/$p->product_id '1' .jpg' height='150' width='150'/>"

"<img src='http://localhost/CodeIgniter/photos/<?php echo $p->product_id; ?>1.jpg' height='150' width='150'/>";

But the image still doesn't show. The table is being generated in my Controller which is a PHP file so I don't really think I need to use php tags


Solution

  • "<img src='http://localhost/CodeIgniter/images/" . $product->product_id . "_1.jpg' height='100' width='100'/>";