1,105,177 Community Members

Check boxes and arrays

Member Avatar
ethio
Newbie Poster
16 posts since Dec 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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
diafol
Where are my eyes?
12,941 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,845 [?]
Skill Endorsements: 90 [?]
Moderator
Featured
Sponsor
 
0
 

$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']);
Member Avatar
veedeoo
Veteran Poster
1,008 posts since Oct 2011
Reputation Points: 314 [?]
Q&As Helped to Solve: 164 [?]
Skill Endorsements: 17 [?]
 
0
 

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

Member Avatar
ethio
Newbie Poster
16 posts since Dec 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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>
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article