从文本文件中增加/添加数据

时间:2012-02-26 00:42:29

标签: php arrays sqlite checkbox

我有一个网页,其中包含来自文本文件的一些数据,选中时会在其他页面上显示已检查的数据。 每次选中复选框时,我都希望将访问字段增加到它,如何在每次访问时增加变量“$ visit”并将其保存到文本文件中?

new.php

<html> 
<body bgcolor="#99FF00">
<table border="1">
<FORM ACTION="new.php" METHOD="POST">
Enter maximum price <input type="text" name="maximumprice"/> 
<p><input type="submit" value="Go" name="Go"/>
</form>

<?

$mPrice = $_POST['maximumprice'];
$file1 = "properties.txt";
$filedata = fopen ($file1, "r");
$array1 = file ($file1); 

print "<form action=\"visit.php\" method=\"POST\">";




for ($counter1 = 0; $counter1 < count($array1); $counter1++) 
{
$arrLine = $array1[$counter1];

$pCode = getvalue ($arrLine, 0);
$price = getvalue ($arrLine, 1);
$picture = getvalue ($arrLine, 2);
$visit = getvalue ($arrLine, 3);



if ($price < $mPrice)
{
print "<tr>";
print "<td>";

print $pCode. "<br>";
print $price. "<br>"; 
//print $picture. "<br>";
print $visit. "<br>";

print "<input type=\"checkbox\" name=\"box[]\" value=\"$arrLine\" />";

print "</td>";

print "<td>";
printf("<img src='$picture' width='200' height='150'>");
print "</td>";
print "</tr>";


} 
} 

print '<input type="submit" name="Visit" value="Visit"/>';

// Move the form outside the for loop
print "</form>";


fclose ($filedata); 

function getvalue ($text, $arrNo) 
{ 
$intoarray = explode (",", $text); 
return $intoarray[$arrNo]; 
} 

?> 

</table>
</body>
</html>

这是第二页,display.php

<html>
<body bgcolor="#99FF00">
<?

foreach ($_POST['box'] as $values)
{
echo "$values <hr/>";
}



?> 
</body>
</html>

1 个答案:

答案 0 :(得分:0)

有几个关于如何在网上执行此操作的教程。

这是一个很棒的教程: http://www.developingwebs.net/phpclass/hitcounter.php

当然每次检查复选框时递增都需要一些AJAX脚本。 除非您正在等待发布数据,然后更新计数器。