1
echo "<img src=\"images/" . $row['filename'] . "\" alt=\"\" /><br />";

How can i embed above PHP code in html. i have image folder in server where i would like to display image.

sanainfotech
  • 571
  • 4
  • 11
  • 29
  • 1
    And what is wrong with your code? It should be ok. But you may have wrong URLs. For instance, try to use `src=\"/images/"` so it will look images folder in site root. as you have it now, on page like www.mysite.com/test/page.html it will try to get image from www.mysite.com/test/images/image.png – Viktor S. Jan 10 '13 at 12:16
  • nothing wrong in the above php code. but i want to display in tables using html . [click here for demo](http://shaadimubarakh.com/display_Search.php) – sanainfotech Jan 10 '13 at 12:30
  • Show you code where $row is taken. Looks like it is simply empty or filename is not taken from database. Or you are using wrong key (filename instead of file_name, for instance) – Viktor S. Jan 10 '13 at 12:35
  • Actually, you can set var_dump($row); and see what is returned there. That way you will check if you have filename in your row at all. – Viktor S. Jan 10 '13 at 12:38
  • yes your right, there are no image file in the images folder with that name – sanainfotech Jan 10 '13 at 12:54
  • Well... I was talking about value of $row['filename'] which looks to be empty (as far as I can see from results of your demo page). But if problem is solved, than ok – Viktor S. Jan 10 '13 at 12:57

5 Answers5

2

You can also try this:

<img src="<?php echo $row['filename'];?>"/><br/>
Chetana Kestikar
  • 570
  • 6
  • 23
1

What's the problem?

But your file must be .php and then insert into html.

<?php echo "<img src=\"images/" . $row['filename'] . "\" alt=\"\" /><br />"; ?>
Norbert Pisz
  • 3,392
  • 3
  • 27
  • 42
1

You can try this:

<img src="images/<?php print $row['filename'];?>" alt="" /><br />
Pupil
  • 23,834
  • 6
  • 44
  • 66
  • Thanks Tried This not working [click this link for demo](http://shaadimubarakh.com/display_Search.php) – sanainfotech Jan 10 '13 at 12:29
  • Hi, Thanks for your comment. I have seen the link. the image path is showing as "http://shaadimubarakh.com/images/". The image base name is missing. Please check. – Pupil Jan 10 '13 at 12:31
0

Try this-

echo "<img src='images". $row['filename']."'  alt=''/><br />";
Suresh Kamrushi
  • 15,627
  • 13
  • 75
  • 90
0

You can embed PHP inside HTML also, you can embed HTML inside your PHP. Both approaches work. But, preferred on is to embed PHP inside HTML. The reason is:

1) PHP parser parses every PHP code.

2) So, if we have written HTML code in PHP, it will parse the code.

3) Hence the load on parser will be more.

4) Where as, HTML tags (codes) as shown directly on the browser (without any parsing)

So always, embedding PHP into HTML is better.

Thanks.

Pupil
  • 23,834
  • 6
  • 44
  • 66