我正在从sql中获取值,并通过为惟一值设置Radio来做出选择。因此,我将value = '<?php $row[' ']..... ;?>'放置在值上,但每次都会出错。看起来我没有正确地在value bcz中传递php,当我删除它时,一切都会变得很好。请给我指路。
代码:
while($row = mysql_fetch_array($query) or die(mysql_error())){
echo '<form>';
while ($row=mysql_fetch_array($query))
{
echo '<div class="boxed" >';
echo "\t".'<tr><th>'.$row['question']."<br>".'</th><th>'."<input type='radio' name='optn' value=' <?php $row['A']; ?> '>".$row['A']."<br>".'</th><th>'."<input type='radio' name='optn' value='<?php $row['B']; ?>'>".$row['B']."<br>".'</th><th>'."<input type='radio' name='optn' value='<?php $row['C']; ?>'>".$row['C']."<br>".'</th><th>'."<input type='radio' name='optn' value='<?php $row['D']; ?>'>".$row['D'].'</th></tr>';
// echo '<tr><th>'.'<font size="5" color=#07c >'."<a href='reply.php?name=$id'>".$row['qtitle']."</a>".'</font>'.'</th><th>'."          ".'<font size="2" color=#07c >'.$row['Date']."   ".$row['Time']."<br>".'</font>'.'</th><th>'.$row['askquestion'].'</th></tr>';
// echo"<th> <a href ='delete.php?name=$id'><center>Delete</center></a></th></tr>";
echo '<input type="submit" name="submit" />';
echo '</div>';
}
echo '</form>';
}错误:
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\New folder\htdocs\website\Quizes.php on line 245发布于 2015-12-27 09:32:19
在引用的字符串中嵌入php标记的方式引起了问题。你会发现它更容易正确格式化代码,海事组织!我认为以下内容应该是可以的,这些值现在被封装在大括号中。
while($row = mysql_fetch_array($query) or die(mysql_error())){
echo '<form>';
while ($row=mysql_fetch_array($query))
{
echo '<div class="boxed" >';
echo "\t".'<tr><th>'.
$row['question']."<br>".
'</th><th>'."<input type='radio' name='optn' value='{$row['A']}'>".$row['A']."<br>".
'</th><th>'."<input type='radio' name='optn' value='{$row['B']}'>".$row['B']."<br>".
'</th><th>'."<input type='radio' name='optn' value='{$row['C']}'>".$row['C']."<br>".
'</th><th>'."<input type='radio' name='optn' value='{$row['D']}'>".$row['D'].'</th>
</tr>';
echo '<input type="submit" name="submit" />';
echo '</div>';
}
echo '</form>';
}下面是一个重写的版本,我认为,它更好地说明了你给出的代码中的问题。
while( $row = mysql_fetch_array($query) or die(mysql_error())){
echo '<form>';
while( $row=mysql_fetch_array( $query ) ){
echo "
<div class='boxed'>
<tr>
<th>
{$row['question']}<br>
</th>
<th><input type='radio' name='optn' value='{$row['A']}'>{$row['A']}<br>
</th><th><input type='radio' name='optn' value='{$row['B']}'>{$row['B']}<br>
</th><th><input type='radio' name='optn' value='{$row['C']}'>{$row['C']}<br>
</th><th><input type='radio' name='optn' value='{$row['D']}'>{$row['D']}</th>
</tr>
<input type='submit' name='submit' />
</div>";
}
echo "</form>";
}没有table标记,但是您有tr和th标记,还有一个嵌套的while循环.
发布于 2015-12-27 09:38:08
由于以下原因,解析错误:
<?php $row['A']; ?>在php脚本中使用它,可以将其用作
". $row['A'] . "https://stackoverflow.com/questions/34479172
复制相似问题