Jump to content


Photo

Help with a For Loop


  • Please log in to reply
1 reply to this topic

#1 reub77

reub77
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 01 May 2006 - 03:37 AM

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:
for ($counter = 1; $counter <= $numcov; $counter++)
    {
      $a .= "User #".$counter.": $fname".$counter." $lname".$counter." Date of Employment: $doe".$counter."\n\n";
    }

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

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

#2 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 01 May 2006 - 08:20 AM

ttry
$a .= "User #$counter: ${fname.$counter} ${lname.$counter} Date of Employment: ${doe.$counter}\n\n";





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users