Reply to Re: Variable in a variable name

Your name:

Reply:


Posted by Scott on 04/13/06 23:02

On Thu, 2006-04-13 at 20:41 +0200, Garry Jones wrote:
> "Jerry Stuckle" <jstucklex@attglobal.net> skrev i meddelandet
> news:1cydncizcunm8aPZnZ2dnUVZ_uudnZ2d@comcast.com...
>
> > Sjoerd is correct - you really want to use arrays. They're much easier
> > than your route, and the code much cleaner.
>
> I have looked at arrays. My problem is that some people only enter their
> christain name and leave the surname blank. Other strange user combinations
> are possible, people can jump to a lower place in the form and use the forth
> group of input fields for the third person for instance.
>
> As I am reading in up to 8 values for each person I saw that I was going to
> have to synchronise the input if I use arrays. Data entered into each of the
> groups of fields has to be kept together. As I am new to arrays and have
> already got the code sorted out I thought a variable name would be the
> simpliest way of doing this.
>
> However, sticking ones head in the mud and refusing to adapt to the correct
> tool for the job never pays in the long term. So a few tips about keeping
> input data in groups so that an array reading does not group together the
> information from different groups of fields would come in very handy for me.
>
> Garry Jones
> Sweden
>
>

Garry,

If your input fields are all text fields, and you assign them variable
names (<input type="text" name="personage[]">), then any empty fields
will simply be an empty string. However, they will still hold a place in
the array.

For example, if the 2nd person enters their age, but the 1st person
doesn't:

$_POST['personage'][0] will equal ''
$_POST['personage'][1] will equal '25' (or whatever age they put in).

The point is, if you have your text fields named personage[] and
personfname[], and have the same fields for each entry, then
$_POST['personage'][2] will correspond with $_POST['personfname'][2].

Does that help?

Scott

[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

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