2012-02-26 11 views
0

テキストファイルの一部のデータが含まれているWebページがあります。チェックすると、チェックされたデータが別のページに表示されます。 チェックボックスをオンにするたびに、visitsフィールドを増やしたいときは、訪問するたびに変数「$ 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> 

これは2ページ目で、display.php

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

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



?> 
</body> 
</html> 

答えて

0

は、ウェブ上でこれを行う方法のいくつかのチュートリアルがあります。

偉大なチュートリアルでは、ここでは1です:毎回チェックボックスをインクリメントもちろん​​ http://www.developingwebs.net/phpclass/hitcounter.php

チェックされているいくつかのAJAXのスクリプトが必要になります。 投稿データが届いてからカウンタを更新するのを待っている場合を除きます。

関連する問題