Jump to content

Storing Array Data


will_1990

Recommended Posts

Hello and thanks for looking!

 

I have stored an looped variable into an array which is in an if statment. The problem im having is that if i echo the array results outside of the loop i do not get the full array just the last entry. I have tried imploding the array frist but the same result occours - here is my code and where i have got to so far... My aim is to get the array result sent accross a form so it can be written to a text file....

 

<form name="info" method="post" action="write_ffdb1.php">
<table  border="1" border-color="black">
   <tr>
   <td> Product Number</td>
   <td> Product Price </td>
   </tr>
<?php
$test;
if(!($lines = file('php_ffdb.txt'))) 
{echo 'ERROR: Unable to open file! </body></html>'; exit;} 
foreach ($_POST as $ID2 => $price) {
foreach($lines as $theline) { 
list($ID, $title, $author, $description, $price, $image) = split('\|',$theline); 
if($ID==$ID2) 


{ 
   echo " 
   <tr>
    <td>$ID</td>
   <td>$price</td>
	</tr>
  
   

     ";   
 $array [7] = "$ID";

$comma_separated = implode(",", $array);
echo ("$comma_separated"); // This displays what i want eg 1,2,3, etc but does not work ouside of the if statement (see below)
$test=$comma_separated; 
 $novatprice += $price;	 





echo ("<input type='hidden' name='$comma_separated'> "); - //i have used this to try and send it to my other form..
}
                              }        
echo("$test"); // this only returns the final looped $ID rather than 1,2,3 ETC

 

I would LOVE any advice or reccomendations on how to do this, any way possible!!

 

thanks for any help or words of wisdom!!

 

Will

Link to comment
https://forums.phpfreaks.com/topic/193495-storing-array-data/
Share on other sites

If you mean take it outside the if statement then it still only prints the final $ID  that is collected ie - the last check box that is clicked.

 

This also happens if i leave the array within the if statement and the print outside the statement.

 

However, if i have both of them in there it functions correctly and both are printed.

 

I thought that once an array has stored the data remains there despite being in the loop or not..... :S

 

Any more thoughts im still completely stuck on this!

Link to comment
https://forums.phpfreaks.com/topic/193495-storing-array-data/#findComment-1018938
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.