The best way to do this is not to call them pick1, pick2, etc.. but call 
them all pick[].

Here's an example:

<select name="pick[]">
    <option value="STL">St. Louis</option>
    <option value="WAS">Washington</option>
</select>
<select name="pick[]">
    <option value="STL">St. Louis</option>
    <option value="WAS">Washington</option>
</select>

Then in your PHP code you can do it like this:

<?php
    foreach ($HTTP_POST_VARS['pick'] as $key => $value) {
        echo $value.'<br />';
    }
?>

or, if you prefer more traditional syntax:

<?php
    for ($i=0; $i<count($pick); $i++) {
        echo $pick[$i].'<br />';
    }
?>

Mike Eheler

JMack wrote:

>Greetings.  I have been playing around with PHP this week, programming a
>football pool.  I have hit a small snag that I would like some assistance
>with, if anyone knows the answer -- it's probably very simple, but my Intro
>to PHP book does not tell me how to do it.
>
>I have an HTML form in a PHP page, with several controls on it.  I am
>dynamically generating the names for these controls.  Here is the example --
>for each game, the user selects the winner in a <SELECT> control.  It's set
>up to not care how many games there are for each week, just dynamically
>build the form/controls and name them "pick1", "pick2", etc.
>
>In my function that handles the form and uploads the user's picks to the
>database (MySQL), I need to also dynamically generate the variable names
>that refer to these controls.  I have them all declared as global variables,
>since I know there will never be more than 15 games in a given week.  But, I
>want to iterate through a loop for each game and update the database.  As I
>loop through for each game, and try to dynamically generate the vaiable
>names for $pick1, $pick2, etc.  I end up trying to update the DB by sending
>in the string "$pick1" instead of the value from the form control for pick1.
>
>I have attached the PHP file in question.  The code is not very clean,
>especially the part where I am having problems, but hopefully, someone will
>have some time to help me with this problem.  Please respond to this
>newsgroup or directly to me at [EMAIL PROTECTED]  Thank you.
>
>Joe Mack
>
>
>
>
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to