Reply to Re: Dynamic Form

Your name:

Reply:


Posted by Jerim79 on 04/04/07 13:13

On Apr 4, 7:47 am, Tyno Gendo <you@localhost> wrote:
> Jerim79 wrote:
> > and passing it along as hidden button on the form. $Age'$Number'
> > seemed to work for creating the variable, but $_post["Age'$Number'"]
> > doesn't work for referencing the global variable. I would need some
> > way of looping through and dynamically creating the variables.
>
> > I am willing to rethink my approach to the whole problem, so the door
> > is wide open to suggestions.
>
> Firstly, I'd get rid of the single quotes at they come out as
> Age'1', but you probably want Age1
>
> For an unknown number of ages you could do:
>
> $ages=array();
> foreach( $POST as $key=>$value ) {
> if (substr($key,0,3)=="Age") {
> $ages[$key]=$_POST[$key];
> }
> }
>
> If there were 5 ages you would end up with
>
> $ages["Age1"] = <age_entered1>;
> $ages["Age2"] = <age_entered2>;
> $ages["Age3"] = <age_entered3>;
> $ages["Age4"] = <age_entered4>;
> $ages["Age5"] = <age_entered4>;
>
> If you don't want an array, you can do:
>
> foreach( $POST as $key=>$value ) {
> if (substr($key,0,3)=="Age") {
> ${$key}=$_POST[$key];
> }
> }
>
> The ${$key} would make your variables $Age1, $Age2 etc.
>
> Hope that helps, untested, let me know.

Thank you so much. It is nice to finally see someone answer my
question right off the bat. Usually when I post these types of
question, I get about 5 "Why are you doing it that way?" type posts,
along with 3 completely off topic responses and at least one "Let me
see your UML." If I am lucky, after about 15 posts, I might get one
half answer such as "Why don't you use an array?" Honestly, thank you
for answering the question. I wish there was a point system so I could
give you some points. I will try either of the suggestions and let you
know.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация