Easy for you, but not for me

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
charlie12345
Forum Newbie
Posts: 14
Joined: Wed Nov 09, 2005 5:35 am

Easy for you, but not for me

Post 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
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Easy for you, but not for me

Post by VladSun »

Honestly, I can't understand anything :)
Please, elaborate.
There are 10 types of people in this world, those who understand binary and those who don't
charlie12345
Forum Newbie
Posts: 14
Joined: Wed Nov 09, 2005 5:35 am

Re: Easy for you, but not for me

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Easy for you, but not for me

Post 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.
Post Reply