这是我在php中的代码 bt它没有按要求工作有问题..输出不是根据这个.. 我试图在wamp服务器上运行它。
<html>
<head>
<title>Binary Search</title>
<style type="text/css">
h1 {color: blue}
</style>
</head>
<body>
<h1 align="center">Computer guess number by using binary search</h1>
<form method="GET">
<?
if (empty($flag_num))
{
$flag_num = -1;
}
if ($flag_num==-1)
{
if (empty($max_num)) $max_num = -1;
if (empty($min_num)) $min_num = -1;
$flag_num = 1;
print <<<Here
<input type="hidden" name="flag_num" value="$flag_num">
<input type="hidden" name="max_num" value="$max_num">
<input type="hidden" name="min_num" value="$min_num">
Input your hidden number: <input type="text" name="hid_num" value="$hid_num"> (1-99)
<br>
<input type="submit" value="Now let's computer guess">
Here;
}
else
{
if ($max_num==-1 && $min_num==-1)
{
$max_num = 100;
$min_num = 0;
$result_num = $hid_num;
}
else
{
if ($comparision == "bigger")
{
$min_num = $guess_num;
}
else if ($comparision == "smaller")
{
$max_num = $guess_num;
}
}
$guess_num = ($max_num + $min_num)/2;
setType($guess_num,"integer");
print "Computer guess <h3> $guess_num </h3>";
if ($guess_num == $result_num)
{
$flag_num = -1;
}
if ($flag_num == -1)
{
print <<<Here
<input type="hidden" name="flag_num" value="$flag_num">
<h1> Congratulation, Computer win </h1>
<input type="submit" value="Next>>>" >
Here;
}
else
{
print <<<Here
<input type="hidden" name="flag_num" value="$flag_num">
<input type="hidden" name="max_num" value="$max_num">
<input type="hidden" name="min_num" value="$min_num">
<input type="hidden" name="guess_num" value="$guess_num">
<input type="hidden" name="result_num" value="$result_num">
<br>
Your intruction: <input type="radio" name="comparision" value="bigger"> Bigger
<input type="radio" name="comparision" value="smaller"> Smaller
<br>
<input type="submit" value="Submit">
Here;
}
}
?>
</form>
</body>
</html>
答案 0 :(得分:0)
您需要使用$_GET['flag_num']
来获取查询参数,而不是$flag_num
。该脚本没有执行任何操作,因为没有任何变量具有任何值。同样,$_GET['max_num']
,$_GET['min_num']
,$_GET['hid_num']
。