Hi all,
I am trying to display some data from text file with an array.

$filename = "comments.txt";
$filepointer = fopen($filename,"r");  
$myarray = file ($filename);
for ($mycount = 0; $mycount < count($myarray); $mycount++ )
    { 
      $aline = $myarray[$mycount];  
print $aline ." \n";
    }
fclose ($filepointer);

If (if else statement-checks search terms)
print $value
print <input type=\"checkbox\" name=\"$aline\" />";

The check boxes show up but, when a user enters a search term only the relevant data will come up with check boxes, my question is how do I display the data that has been checked on a different PHP file? I know it has to do with

$_POST["$aline"];

but it's not working.

Member Avatar for diafol

$aline will probably not be set in the receiving file, so you won't be able to reference it, unless you do something like this:

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

Now you can pick up all aline posts as an array:

print_r($_POST['lines']);

please ignore... ardav already got it covered :)

Its giving me nothing, just an empty page.

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

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

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 "<form action=\"available.php\">";
print "$arrLine<input type=\"checkbox\" name=\"box[]\" value=\"$arrLine\" />";
print "</form>";
print "</td>";

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



}
} 

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

</table>
</body>
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.