简体   繁体   English

php Javascript变量引用错误

[英]php Javascript variable quoting error

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. 图片数据URL“ PicNotes”是从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. 我在3个版本(尝试)中添加了一些rem语句,以使其正常运行。

    $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='&lt;b&gt;".$row['Title']."&lt;/b&gt;&lt;br /&gt;".$row['Medium']." &nbsp; &nbsp; &nbsp; ".$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. 请有人能使我走上正确的道路。

1) Escape the inner quotes: 1)转义内部引号:

$icon = "<a href=\"JavaScript:Popup(notes/$row[PicNotes])\"><img src=images/info.png></a>";

2) Use single quotes: 2)使用单引号:

$icon = "<a href='JavaScript:Popup(notes/$row[PicNotes])'><img src=images/info.png></a>";

使用花括号({})进行更好的变量连接

$icon="<a href=\"JavaScript:Popup('notes/{$row[PicNotes]}');\"><img src=\"images/info.png\"></a>";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM