我试过这样的事情:
// $count is an incrementing number
echo '<td><input type = "radio" name = "selected"
value = "<?php echo htmlspecialchars($count); ?>"></td>';
我也尝试过:
echo '<td><input type = "radio" name = "selected" value = "<?php echo
"$count"; ?>"></td>';
并且都没有奏效。我意识到尝试用这种方式用PHP编写html似乎很奇怪,但我不知道如何根据某些条件显示html。
添加代码段所在的整个功能:
function makeRow($row_name,$row_ticket) {
//create html table row from mysql table row passed as ticket object param
$count = 0;
foreach ($row_array as $key => $value) {
# code...
$count++;
if(strcmp($key, "select")==0){
echo '<td><input type = "radio" name = "selected"
value ="' . <?php echo htmlspecialchars($count); ?> . '"></td>';
}
else if(strcmp($key, "body")==0){/*do not make cell for body*/}
else { echo "<td>$value</td>";}
}
}
答案 0 :(得分:1)
为什么不连接字符串和嵌入式<?php
:
// $count is an incrementing number
echo '<td><input type = "radio" name = "selected"
value ="' . <?php echo htmlspecialchars($count); ?> . '"></td>';
注意:我还认为您对PHP和HTML的解释存在根本的误解:
<td>
<input type="radio" name="selected" value="<?php echo "$count"; ?>">
</td>
答案 1 :(得分:1)
它无法正常工作,因为您无法连接一个字符串,就像它会抛出php解析错误一样。我没有足够的评论声誉,所以我添加了自己的答案:
// $count is an incrementing number
echo '<td><input type = "radio" name = "selected"
value ="' . htmlspecialchars($count) . '"></td>';
您无法在另一个内添加新的php打开/关闭标记。
更新
实际上,你不需要htmlspecialchars()函数来输出脚本生成的整数变量,所以你也可以跳过它。