meshhat Posted June 7, 2007 Share Posted June 7, 2007 Hello, I'll start by saying I'm a complete newbie to php. I think what I want to do is fairly simple, though. I'm trying to pass 100 variables (named gain1, gain2...gain100) from a swf to a php file then write these variables to a text file. Sending the data works fine. I just need help creating the variables in the php file. Since all the files have partly the same name, I was hoping to create the variables dynamically. I was hoping to do something like this: $myFileName = "myfile.txt"; $myFileHandle = fopen($myFileName, 'a') or die("can't open file"); for (i=1; i<100; i++) { $gaintext + i= $_POST['gaintxt1' + i]; fwrite($myFileHandle, $gain + i); } However, this isn't working obviously. Any help? Link to comment https://forums.phpfreaks.com/topic/54519-creating-dynamic-variables/ Share on other sites More sharing options...
Yesideez Posted June 7, 2007 Share Posted June 7, 2007 Try this: for ($i=1; $i<100; $i++) { $gaintext=$_POST['gaintxt1'.$i]; fwrite($myFileHandle, $gaintext); } I've never grabbed data from a flash file beforeso I've no idea if this will work. Link to comment https://forums.phpfreaks.com/topic/54519-creating-dynamic-variables/#findComment-269651 Share on other sites More sharing options...
trq Posted June 7, 2007 Share Posted June 7, 2007 Are these the only variables being posted by the form? <?php $myFileName = "myfile.txt"; $myFileHandle = fopen($myFileName, 'a') or die("can't open file"); foreach($_POST as $val) { fwrite($myFileHandle, $val); } ?> Link to comment https://forums.phpfreaks.com/topic/54519-creating-dynamic-variables/#findComment-269659 Share on other sites More sharing options...
meshhat Posted June 7, 2007 Author Share Posted June 7, 2007 Thanks for the responses. Actually no, there are 3 variables being passed. All the same concept though: gain1, gain2, ...gain100 loss1, loss2, ...loss100 net1, net2, ...net100 Yesideez, that didn't seem to work. I'm passing the variables via a POST. The following variables give me the first respective variable: $gain = $_POST['gain1']; $net = $_POST['net1']; $loss = $_POST['loss1']; I just don't want to do this 100 times for each. thorpe, I'll try your recommendation. Link to comment https://forums.phpfreaks.com/topic/54519-creating-dynamic-variables/#findComment-269674 Share on other sites More sharing options...
trq Posted June 7, 2007 Share Posted June 7, 2007 I should have actually asked. Do you want ALL values from the $_POST array written to the file? If so... the above method I posted should work. Link to comment https://forums.phpfreaks.com/topic/54519-creating-dynamic-variables/#findComment-269678 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.