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
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";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.