现在我做了很多研究,在 PHP 中尝试了很多方法,包括 $_POST isset.. foreach 等
但我需要一些帮助!
基本上,只想检查复选框是否已被选中。然后,如果复选框已被选中,则将 $visits 的数量加 1。
只要我可以检查复选框是否被选中,我想我可以从那里弄清楚!
提前致谢
(注意:$visits 是访问属性的次数。此编码显示从文件中读取的属性信息)
<?
$filename = "house.txt";
$filepointer = fopen($filename,"r"); // open for read
?>
<html>
<head>
<h1> Search for properties</h1>
<form method = "post" action= "visit.php">
Enter max price
<input type = "text" name = "max" value="<?=$Max;?>">
<input type = "submit" name = "submit">
<br><i><p>Properties found</p></i></br>
</form>
</head>
</html>
<?
$myarray = file ($filename);
for ($mycount = 0; $mycount < count($myarray); $mycount++ ) { // one input line at a time
$aline = $myarray[$mycount];
$postcode = getvalue($aline,0);
$value = getvalue($aline,1);
$image = getvalue ($aline,2);
$visits = getvalue($aline,3);
$Max = $_POST['max'];
if ($value < $Max) {
print "<table border = 2>";
print "<FORM METHOD='POST' ACTION='visit.php' >";
print "<td> <input type='checkbox' name='check' value='Yes' > $postcode </td><BR> \n";
print "<td>$value <BR>";
print "<td>$image<BR>";
print "<td>$visits<BR><p>";
print "</table>";
print "</form>";
}
}
function getvalue ($aline, $commaToLookFor) {
$intoarray = explode(",",$aline);
return $intoarray[ $commaToLookFor];
}
if (isset($_POST['check']) && $_POST['check'] == 'Yes') {
echo "checked!";
} else {
echo "not checked!.";
}
?>