Jump to content

Archived

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

reub77

Help with a For Loop

Recommended Posts

I'm having issues trying to retrieve variables in a For Loop. The page I'm trying to do this on is retrieving a number of variables defined by the user. If the user states they need to add 10 users to teh system then I need to retrieve 4 variables associated with each user. Each variable is named with a number at the end.

eg.

First Name would be $fname1
Last Name would be $lname1
Date of Employment would be $doe1

Now, if 18 users are required I then allow the user to enter this info for all 18 users. The trouble I'm having is calling all this data to be inserted into a mail function.

Here's my code:
[code]
for ($counter = 1; $counter <= $numcov; $counter++)
    {
      $a .= "User #".$counter.": $fname".$counter." $lname".$counter." Date of Employment: $doe".$counter."\n\n";
    }
[/code]

I'm counting on being able to use the number in the variable name to call each of the user defined amount of variables. Is my code correct? Is there a better way to do this?

Thanks

[b]EDITED BY WILDTEEN88: PLEASE USE THE CODE TAGS WHEN SUBMITTING CODE. THE PHP TAGS NO LONGER EXIST[/b]

Share this post


Link to post
Share on other sites
ttry[code]$a .= "User #$counter: ${fname.$counter} ${lname.$counter} Date of Employment: ${doe.$counter}\n\n";[/code]

Share this post


Link to post
Share on other sites

×

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.