Reputation: 691
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.
Upvotes: 1
Views: 3693
Reputation: 23968
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.
Upvotes: 0
Reputation: 23968
You can try this:
<img src="images/<?php print $row['filename'];?>" alt="" /><br />
Upvotes: 1
Reputation: 570
You can also try this:
<img src="<?php echo $row['filename'];?>"/><br/>
Upvotes: 2
Reputation: 16086
Try this-
echo "<img src='images". $row['filename']."' alt=''/><br />";
Upvotes: 0
Reputation: 3440
What's the problem?
But your file must be .php and then insert into html.
<?php echo "<img src=\"images/" . $row['filename'] . "\" alt=\"\" /><br />"; ?>
Upvotes: 1