Sam
Sam

Reputation: 93

PHP+HTML Syntax

I am trying to get a webpage to display four divs that will hold an img and a description. I would like to use a loop because I will have other pages with many of these divs. Here is the code I am using now:

for ($i=0;$i<4;$i++)
{
    echo '<div class="item">
    <img src="IMGs\\' . $items[$i]["ImgFilename"] . '" />
    <h6 class="panel">Description</h6>
    </div>';
}

I believe the problem is that I am not escaping the correct way. I have been searching for a while but cannot find the right combination. Files are stored in IMGs\file.jpg where file.jpg is pulled from the array.

Upvotes: 0

Views: 70

Answers (3)

Anthony Sterling
Anthony Sterling

Reputation: 2441

You can lay that code out a little better by breaking in/out of PHP as required, here's a quick example:-

<?php for($index = 0; $index < 4; $index++): ?>
    <div class="item">
        <img src="IMGs/<?php echo $items[$index]["ImgFilename"]; ?>" />
        <h6 class="panel">Description</h6>
    </div>
<?php endfor; ?>

Upvotes: 1

Christian-G
Christian-G

Reputation: 2361

Your escaping seems fine to me. However, I think the problem is with the double backslash. Eg, remove the \\ and replace it with / So that line becomes:

<img src="IMGs/' . $items[$i]["ImgFilename"] . '" />

Upvotes: 3

Piegus
Piegus

Reputation: 19

U dont need to escape this. change this:

<img src="IMGs\\' . $items[$i]["ImgFilename"] . '" />

to <img src="IMGs/' . $items[$i]["ImgFilename"] . '" />

Upvotes: 1

Related Questions