Help with PHP Development Issue

Discussion in 'PHP' started by lukefowell89, Jun 19, 2010.

  1. #1
    Hi,

    I am currently developing a website for a football team, but I have run into a problem with development and cannot think of any ways to make it work.

    I need to be able to add results for games, but their are 2 different squads in the club with different fixtures. At the moment when you select one of the squads, Ajax dynamically generates a drop down list of opponent fixtures for that squad. This then changes the text below and allows you to enter the goals scored for each team.

    After you have entered 2 valid scores, a list of all the players in the club from a database of players. appears in a list below, which allows you to select via checkboxes if they played or not. A radio button for all players if they were the Man of the Match, and a drop down list for each player to indicate how many goals they scored in the game.

    I need this so I can run statisitics on each player and create a top scorers table etc.

    At the moment I am creating a list like so:-

    Player Name (Drop Down List for Goals) (Checkbox if played) (Radio button if Man of the Match.)

    My problem is, i dont know how to determine which player, which entry is for as the form fields are dynamically generated, and cannot be static.

    At the moment I thought I would make the form name like: -

    <input type="checkbox" name="played_'.$playedId.'" value="1" />

    So if they played the name of the checkbox would indicate their number, and I would extract that using the explode functions from PHP to get the number or regex.

    But I don't know how to return the name of a post variable :S

    So I am stuck, and need a solution.... can anyone think of alternative way of me doing this? or give me some clues etc. All help would be greatly appreciated!!!

    Thanks
     
    lukefowell89, Jun 19, 2010 IP
  2. Zerix

    Zerix Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You could have:

    name="played[$playedId]"

    which will create an array of $played, and then use a foreach loop and try to match it to a players ID? That is, if I have understood your problem correctly.
     
    Zerix, Jun 19, 2010 IP
  3. darkdrgn2k

    darkdrgn2k Active Member

    Messages:
    159
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #3
    or you could loop throught your $_POST using foreach ($_POST as $field=>$value) { ... }
    Each iteration will be a differnt $field and its corresponding value

    Reminder, of checkbox is NOT checked.. value does not get passed at ALL! to solve that problem i have done
     
    darkdrgn2k, Jun 19, 2010 IP