You are here: Re: Dynamic Form « PHP Programming Language « IT news, forums, messages
Re: Dynamic Form

Posted by Tyno Gendo on 04/04/07 12:47

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.

 

Navigation:

[Reply to this 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

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