Jump to content

[SOLVED] Problem with ECHO code


raytri

Recommended Posts

Hi. I'm a new member and pretty new to PHP. My apologies if this question has been answered a hundred times before:

 

When I write the following code:

 

echo '<tr><td><a href="javascript:PopupPic(\'../images/popups/landscapes/'$BigImage'\')"><img src="../images/landscapes/'$Image'" class="gallery" alt="'$Title'" /></a><br /><p class="title">'$Title'</p><p class="description">'$Width'” x '$Height'”</p><p class="sold">'$IsItSold'</p></td>';

 

I get the following error:

 

Parse error:  parse error, unexpected T_VARIABLE, expecting ',' or ';'

 

I can't spot the problem. I think I've properly escaped the single quotes in the echoed portion, and there's no missing bracket errors that I know of.

 

For what it's worth, here's the full code section. Note that the "elseif" and "else" echos are enclosed in double quotes (with double quotes escaped) rather than single quotes; I'm trying to fix the above coding problem before changing them.

 

while ($myrow = mysql_fetch_array ($result))

{

if ($column == 1)// first column display

{

echo '<tr><td><a href="javascript:PopupPic(\'../images/popups/landscapes/'$BigImage'\')"><img src="../images/landscapes/'$Image'" class="gallery" alt="'$Title'" /></a><br /><p class="title">'$Title'</p><p class="description">'$Width'” x '$Height'”</p><p class="sold">'$IsItSold'</p></td>';

$column=2;

}

 

elseif ($column == 2)// second column display

{

echo "<td><a href=\"javascript:PopupPic('../images/popups/landscapes/"$BigImage"')\"><img src=\"../images/landscapes/"$Image"\" class=\"gallery\" alt=\""$Title"\" /></a><br />

<p class=\"title\">"$Title"</p>

<p class=\"description\">"$Width"” x "$Height"”</p>

<p class=\"sold\">"$IsItSold"</p>

</td>";

$column=3;

}

 

else// third column display

{

echo "<td><a href=\"javascript:PopupPic('../images/popups/landscapes/"$BigImage"')\"><img src=\"../images/landscapes/"$Image"\" class=\"gallery\" alt=\""$Title"\" /></a><br />

<p class=\"title\">"$Title"</p>

<p class=\"description\">"$Width"” x "$Height"”</p>

<p class=\"sold\">"$IsItSold"</p>

</td></tr>";

$column=1;

}

$count += 1;

}

 

Thanks for any help you can give a newbie.

 

Link to comment
https://forums.phpfreaks.com/topic/146381-solved-problem-with-echo-code/
Share on other sites

Proper code highlighting...

echo '<tr><td><a href="javascript:PopupPic(\'../images/popups/landscapes/'$BigImage'\')"><img src="../images/landscapes/'$Image'" class="gallery" alt="'$Title'" /></a><br /><p class="title">'$Title'</p><p class="description">'$Width'” x '$Height'”</p><p class="sold">'$IsItSold'</p></td>';

 

and we see our culprits (in blue).

 

To join strings together use concatenation operator (.)

 

echo 'something'.$variable.'something else';

 

You can also use double quotes

 

echo "something $variable something else";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.