Page 1 of 1

Easy for you, but not for me

Posted: Fri Jan 23, 2009 6:48 pm
by charlie12345
Being a 'Newie', (I'm 59 and started out in paper tape and punch cards) I thought I play around a bit and try to learn about php.
So here's my problem/question:
I have a $_POST coming in, and I want to change it from:

Code: Select all

 
 
for ($item = 1; ; $item++) 
{
     $_POST["project"].$item1;
           so I end up the first time with
     $_POST["project1"];
           becuase that's variable beng passed to me in the $_POST:   $_POST["project1"];
etc.
}
 
Make any sense?

Charlie

Re: Easy for you, but not for me

Posted: Fri Jan 23, 2009 7:04 pm
by VladSun
Honestly, I can't understand anything :)
Please, elaborate.

Re: Easy for you, but not for me

Posted: Fri Jan 23, 2009 7:16 pm
by charlie12345
I am being passed in separate variables $_POST["project1"], $_POST["project2"], $_POST["project3"], etc. but I don't know how many there will be; hence my FOR loop, so I thought maybe the best idea was to try to add a number to each $_POST...

Does that help ?

Charlie

Re: Easy for you, but not for me

Posted: Fri Jan 23, 2009 9:31 pm
by requinix
You were close.

Code: Select all

$_POST["project" . $item]
But there's a better way of doing it. Instead of naming the textboxes project1, project2, etc. name them project[].

Code: Select all

<input type="text" name="project[]">
Then $_POST["project"] will be an array, and you can use foreach to loop over it.