NYCPHP Meetup

NYPHP.org

[nycphp-talk] Cycling through posted variables

Brent Baisley brent at landover.com
Thu Jul 11 11:35:56 EDT 2002


Thanks. Actually I was just about to go on that train of thought based on
some reading I was doing. The variable names are generated on the fly. I
think your suggestion may work.

...and I just tried it and it does.  Thanks!

> Are you generating those variable names on the fly while drawing the form ?
> 
> You might be able to get the variables in an array.. Try the following..
> 
> let's say you're working on game 13 and 45.. name your radio buttons (each set
> of them I per game) as
> 
> name=game[13]
> ..
> ..
> name=game[45]
> 
> WHen this is submitted, you can just traverse the 'game' array which will have
> game id as the index and the value being the user's pick for that particular
> game. Obviously you can automate the creation of the form by using a variable
> as the index.. (name=game[$current_id])
> 
> Good luck.
> 
> Oktay Altunergil
> 
> PS: completely untested (not that there's code in the message.. but anyway :P
> )
> 
> On Thu, 11 Jul 2002 10:39:29 -0400
> Brent Baisley <brent at landover.com> wrote:
> 
>> Thanks, I know that works. I should have been clearer. I actually only want
>> to cycle through some of the fields, not all. For instance, other fields
>> that are posted are the player ID, Week ID, and number of Games.
>> 
>> So I really want to just grab a subset of all the posted fields, the subset
>> being the first (or last) x fields, x being the number of games. I know I
>> could use the loop below with an incrementing variable and an exit, but I
>> just feel that I'm missing something more elegant.
>> 
>>> foreach($_POST as $var => $val) {
>>> echo "The field named $var has the value $val<br>\
";
>>> }
>>> 
>>> -----Original Message-----
>>> From: Brent Baisley [mailto:brent at landover.com]
>>> Sent: Thursday, July 11, 2002 9:05 AM
>>> To: NYPHP Talk
>>> Subject: [nycphp-talk] Cycling through posted variables
>>> 
>>> I'm trying to cycle through the "fields" posted through a form submit. I
>>> need to cycle through the "fields" because I won't know the names of the
>>> fields since the field name actually represents a value. I tried going
>>> through the $HTTP_POST_VARS route and $_POST. Since this is suppose to be an
>>> array, I thought I could cycle through using something like $_POST[0][1],
>>> but this doesn't seem to work.
>>> For testing, if I do $_POST["Game1"], then it works. Any ideas what I'm
>>> doing wrong or a better approach?
>>> 
>>> Why do I need to do something like this? Well, I'm designing a system to
>>> handle a football pool I manage every year. This piece is for submitting a
>>> users picks for the week. I want the field name to be the Game ID and the
>>> value would be the Team ID. The picks screen uses radio buttons and the user
>>> picks the winner for each game. All games for the week (~12) are displayed
>>> at once for convenience.
>>> 
>>> I'm using PHP 4.1.2 (on OSX), but can upgrade if need be. I probably should
>>> anyway.
>>> 
>>> Thanks
>>> --
>>> Brent Baisley
>>> Systems Architect
>>> Landover Associates, Inc.
>>> Search & Advisory Services for Advanced Technology Environments
>>> p: 212.759.6400/800.759.0577
>>> 
>> 
>> -- 
>> Brent Baisley
>> Systems Architect
>> Landover Associates, Inc.
>> Search & Advisory Services for Advanced Technology Environments
>> p: 212.759.6400/800.759.0577
>> 
>> 
> 

-- 
Brent Baisley
Systems Architect
Landover Associates, Inc.
Search & Advisory Services for Advanced Technology Environments
p: 212.759.6400/800.759.0577




More information about the talk mailing list