Click to See Complete Forum and Search --> : In Need of some help!!!!


gogelpot
01-18-2007, 05:46 AM
Hi I have a problem that I need some help with.

I have a form that POST data to my php script, the field names are created on the fly.

exp. $Bat1_player1, $Bat1_player2, $Bat1_player3 ect.

In my script I want to use a while loop to create the fields again, but this is where the problems starts. I use the following statment.

if (isset($_POST['Bat1_player1'])) $Bat1_player1 = $_POST{'Bat1_player1'];

but need to replace the 1 at the end of "{'Bat1_player1'];"

How can this be done?

Could some body pls help.

MatMel
01-18-2007, 07:17 AM
Try this:


if (isset($_POST['Bat1_player' . $x])) {
$var = "Bat1_player" . $x;
$$var = $_POST{'Bat1_player' . $x];
}


You could also think of using an array... I think that would be more useful ...

NightShift58
01-18-2007, 07:24 AM
If instead of calling your POST fields $Bat1_player1, you would call your fields $Bat1_player[] then you would be able to do the following, without having to know how many have been defined in the <form>:<?php
$arrBat1_players = $_POST['Bat1_player'];
FOREACH ($arrBat1_players as $key =>$thisPlayer) :
echo $thisPlayer;
// or ...
echo $arrBat_players[$key];
ENDFOREACH;
//and, if you need to know how many there were:
$Count_Players = count($arrBat1_players);
?>