【问题标题】:Incrementing/Adding data from a text file从文本文件中增加/添加数据
【发布时间】:2012-03-16 00:14:54
【问题描述】:

我有一个网页,其中包含来自文本文件的一些数据,选中时会在不同页面上显示选中的数据。 每次选中复选框时,我都想增加访问字段,如何在每次访问时增加变量“$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>

【问题讨论】:

    标签: php arrays sqlite checkbox


    【解决方案1】:

    网上有几个关于如何做到这一点的教程。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-09
      • 1970-01-01
      • 2014-04-03
      • 2019-05-10
      相关资源
      最近更新 更多