Jump to content

Recommended Posts

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

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.

 

 

 

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.