Reputation: 21
I'm having trouble with quotes in a line of the attached code.
It is part of a picture viewer. Picture data url "PicNotes" is read from mysql. I am attempting to enhance the result by adding a picture info pop-up but can't get the quotes right.
I have added some rem statements around 3 versions (attempts) to get it working.
$data = mysql_query("SELECT * FROM $tbl_name WHERE type='$type' LIMIT $start, $limit_col_1");}
// Your while loop here
while($row = mysql_fetch_array($data))
{//REM If there is no info don't show the info link
if ($row[PicNotes]) {
// $icon=<a href="JavaScript:Popup('notes/$row['PicNotes']');"> <img src='images/info.png'></a>; //REM This line was the original call for the pop-up script
// $icon = "<a href=notes/tempest_series.php><img src=images/info.png></a>"; //REM This line works but does not have any of the Jarvascript or URL variable from the DB
// $icon = "<a href=notes/$row[PicNotes]><img src=images/info.png></a>"; //REM This line doesn't crash but the URL is corrupted
$icon = "<a href="JavaScript:Popup(notes/$row[PicNotes]);"><img src=images/info.png></a>"; //REM This line crashes with an "Unexpected T_STRING error
}else{
$icon='';}
// Display LHS Thumbnail and Viewer Pic Data
echo "<a href='images/".$row['vfile']."' rel='enlargeimage::mouseover' rev='loadarea' title='<b>".$row['Title']."</b><br />".$row['Medium']." ".$row['iw']." x ".$row['ih']." cm. $icon'><img border='1' src='images/".$row['tnfile']."
' alt='' width='".$row['tnx']."' height='".$row['tny']."' class='tn' /></a><br />";
}
Please can somebody put me on the right track.
Upvotes: 0
Views: 62
Reputation: 775
Use curly braces ({}) for better variable concatenation
$icon="<a href=\"JavaScript:Popup('notes/{$row[PicNotes]}');\"><img src=\"images/info.png\"></a>";
Upvotes: 0
Reputation: 219804
1) Escape the inner quotes:
$icon = "<a href=\"JavaScript:Popup(notes/$row[PicNotes])\"><img src=images/info.png></a>";
2) Use single quotes:
$icon = "<a href='JavaScript:Popup(notes/$row[PicNotes])'><img src=images/info.png></a>";
Upvotes: 1