Jump to content

Help with a For Loop


reub77

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]
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.