Try:

for($i=0;$i<$count;$i++)
{
  // in the global array, print the variable with the name: "item$i"
  print $GLOBALS["item$i"];
}

or even:

for($i=0;$i<$count;$i++)
{
  // in the post vars array, print the variable with the name: "item$i"
  // this one is probably more secure.
  print $HTTP_POST_VARS["item$i"];
}

Also, as an aside, unlike concatenation in vbscript (blech) you don't have
to break out of quotes all the time. That's because like in perl, php
variables within double quotes are interpolated.

So instead of writing:
print("<input type=text name=item" . $i . ">");

you may write:
print ("<input type=text name=item$i>");

Further, you don't need parenthesis with the print statement so you can
write:
print "<input type=text name=item$i>";

It's just a matter of preference, but I think it looks cleaner.

When concatenating several variables together into a string this can save a
ton of keystrokes and is easier to read and maintain.

Regards,
Matt.



----- Original Message -----
From: "David Mitchell" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, November 10, 2001 9:19 AM
Subject: [PHP] Total Newbie - concatenating variables.


> Hi,
>
> This is my first foray into PHP (coming from a VB, ASP background). What I
> am trying to do should be ridiculously easy, but for some reason I can't
> figure out how to do this.
> I have a form that builds a dynamic number of text boxes in a loop:
>
> for($i=0;$i<$count;$i++)
> {
> print("<input type=text name=item" . $i . ">");
> }
>
> that works fine. I end up with a number of textboxes named "item0",
"item1",
> "item2" and so on...When I submit the form, I pass over the $count value
and
> I want to loop through the count so that I can ge the value for each
textbox
> by building the textbox name dynamically. For example:
>
> for($i=0;$i<$count;$i++)
> {
> print("$item . $i");
> }
>
> Trying to print the value of "$item0", "$item1", etc...Obviously this
> doesn't work. What am I overlooking here?
>
> Many thanks in advance,
>
> Dave
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to