will_1990 Posted February 26, 2010 Share Posted February 26, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/193495-storing-array-data/ Share on other sites More sharing options...
ocpaul20 Posted February 27, 2010 Share Posted February 27, 2010 What happens if you take that piece of code outr of the program and just run it on its own? Anyway, I guess you have probably fixed it by now. Debugging is easier when you just debug the bits that dont work on their own. Quote Link to comment https://forums.phpfreaks.com/topic/193495-storing-array-data/#findComment-1018845 Share on other sites More sharing options...
will_1990 Posted February 27, 2010 Author Share Posted February 27, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/193495-storing-array-data/#findComment-1018938 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.