Forum Moderators: coopster

Message Too Old, No Replies

Display Images Using Names In Database

concatenation

         

oceanwave

9:23 pm on Aug 20, 2007 (gmt 0)

10+ Year Member



This should be easy, but I keep getting error messages.

This works fine, gives me the photo names in one row in a database.

while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['photo1'] . '">' "</td>";
echo "<td>" . $row['photo2'] . "</td>";
echo "</tr>";
}

Now instead of the name, I want to display the images.

So I need:

echo "<td>" <img src="/photos/thumbs/. $row['photo1'] . '">' "</td>";

How do I write these echo lines to display the photos (without parse error, or quotation mark errors)?

willybfriendly

9:30 pm on Aug 20, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Escape your quotes:

echo "<td><img src=\"/photos/thumbs/$row['photo1']\"></td>";

or, use heredoc syntax:

$msg =<<<EOF
<tr>
<td><img src="photos/thumbs/$row['photo1']"></td>
<td><img src="photos/thumbs/$row['photo2']"></td>
</tr>
EOF;

echo $msg;

Receptional Andy

9:32 pm on Aug 20, 2007 (gmt 0)



You need to 'escape' the quotes that are actually part of the output. Have a look at the double quotes section of the string entry in the PHP manual [php.net]

Edit: beat me to it willybfriendly!

[edited by: Receptional_Andy at 9:33 pm (utc) on Aug. 20, 2007]

oceanwave

10:58 pm on Aug 20, 2007 (gmt 0)

10+ Year Member



Thank you so much for answering.

That was one of the things I tried. Tried your code suggestion echo "<td><img src=\"/photos/thumbs/$row['photo1']\"></td>"; again and got the error...

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

oceanwave

11:49 pm on Aug 20, 2007 (gmt 0)

10+ Year Member



Thank you both again. This seems to work:

echo "<td><img src='photos/thumbs/" . $row[photo1] . "'></td>";