我有一个 PHP 循环,其中包含循环内的查询我设置了两个变量以包含某些结果,然后我想在循环外使用这些变量。但是,当我这样做时,它们只是返回未定义。代码如下:
<?php
$standardresult = mssql_query("SELECT Price FROM Extras WHERE ExtraID = 5 ");
while ($standardrow = mssql_fetch_array($standardresult )) {
$toughresult = mssql_query("SELECT Price FROM Extras WHERE ExtraID = 6 ");
while ($toughrow = mssql_fetch_array($toughresult)) {
$toughprice = $toughrow['Price'];
$standardprice = $standardrow['Price'];
echo $standardrow['Price'];
echo $toughrow['Price'];
?>
<td align="center">
<input type="radio" name="triple" value="yes" onclick="showPrice('<?php echo $standardrow['Price']; ?>','<?php echo $toughrow['Price']; ?>')" /> yes
</td>
<td> </td>
<td align="center">
<input type="radio" name="triple" value="no" onclick="showPrice('0','0')" checked="checked" /> no
</td>
<?php
}
}
?>
</tr>
</table>
<input type="hidden" name="ToughPrice" value="<?php echo $toughprice; ?>" />
<input type="hidden" name="StanPrice" value="<?php echo $standardprice; ?>" />
有问题的变量是 $toughprice 和 $standardprice。谁能告诉我哪里出错了,或者如果可能的话?感谢您的任何帮助。