Jump to content

Complex MySQL query


Perad

Recommended Posts

I have come up with a loop which generates a form. I am pretty stunned that it worked first time 8).

Anyway, i need to transfer data from this form into a database. Because the form size is constantly varying i don't know where i would start. Would i need to use a loop to generate a mysql command?

[code]Heres my loop to generate the form.
if ($players !== 0) {
echo '<form id="form2" name="form2" method="post" action="">';
echo 'UNC<br /><br />';
    for ($i=0;$i<$players;$i++) {
if (($players/2)==$i) {
echo '<br /><br />Opponent<br />Player:<input type="text" name="player'.$i.'" size="35" maxlength="35" /><br />';
} else {
      echo 'Player:<input type="text" name="player'.$i.'" size="35" maxlength="35" /><br />';
}
    }
echo '</form>';
  } [/code]

Any ideas on how i would handle this form?
Link to comment
Share on other sites

[quote author=effigy link=topic=112677.msg457413#msg457413 date=1161787209]
The name of the inputs should be[tt] [/tt], which will come across as an array named[tt] $_POST['player'][/tt]. You can then loop through the array and run your SQL statements.
[/quote]

Could you explain this more, do you mean...

player[<input type="text" name="player'.$i.'" size="35" maxlength="35" />]

Link to comment
Share on other sites

Change all of your inputs to [tt]<input type="text" name="player[]" size="35" maxlength="35" />[/tt] and add [tt]echo '< pre>', print_r($_POST, 1), '< /pre>';[/tt] to the submission page. Then submit and see what happens.

P.S. Take the spaces out of the pre tags.
Link to comment
Share on other sites

Sorry to take so long, until you editted it your post didn't make a great deal of sense :)

It comes back with
[code]Array
(
    [player] => Array
        (
            [0] => 1
            [1] => 2
        )

    [submit2] => Next
)[/code]

1 and 2 being the values which i put in. How would i incorporate this into a loop?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.