我有一段代码正在努力。我希望 onclick 函数在函数中显示"问题"行,但是当我'$questionrow['QuestionContent']'
放在括号内时,它给了我一个错误,指出:
解析错误:语法错误、意外T_ENCAPSED_AND_WHITESPACE、第 119 行的/xxx7/Mobile_app/previousquestions.php 中预期T_STRING或T_VARIABLE或T_NUM_STRING
如何在下面的功能中正确将问题内容放在括号内:
onclick='parent.addwindow('$questionrow['QuestionContent']');'>Add</button>
下面是整个代码:
<?php
$output = "";
while ($questionrow = mysql_fetch_assoc($questionresult)) {
$output .= "
<table>
<tr>
<td class='questiontd'>{$questionrow['QuestionContent']}</td>
<td class='addtd'><button type='button' class='add' onclick='parent.addwindow('$questionrow['QuestionContent']');'>Add</button></td>
</tr>";
}
$output .= " </table>";
echo $output;
?>
像处理第一个一样{}
它周围:
'parent.addwindow('{$questionrow['QuestionContent']}');'>
我发现关闭字符串并与句点连接要容易得多。它比将它们封装在大括号中更容易阅读。
<?php
$output = "";
while ($questionrow = mysql_fetch_assoc($questionresult))
{
$output .= "
<table>
<tr>
<td class='questiontd'>" . $questionrow['QuestionContent'] . "</td>
<td class='addtd'><button type='button' class='add' onclick='parent.addwindow('" . $questionrow['QuestionContent'] . "');'>Add</button></td>
</tr>";
}
$output .= "</table>";
echo $output;
?>