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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.