Jump to content

Complicating Question


yarub

Recommended Posts

Who knows.. maybe it's not really that complicating. But it's driving me insane. And I don't even know what to search to find the answer.

 

I am putting together a tournament / gaming bracket for a game we're playing at work. Basically, it shows all of the teams in a list. Here's what I want to do.

 

This is how I have it now. It will ultimately list out all of the teams with a checkbox next to them.

 

[ ] Team 1

[x] Team 2

[ ] Team 3

[x] Team 4

[x] Team 5

 

I have selected Team 2, Team 4, and Team 5 to play in the match. This is what I want to do and I don't know how to do it. How could I then create three rows into a new table with this information?

 

INSERT INTO table (teamid, team, etc, etc, etc) VALUES ('2', 'Team 2', '', '' ,'');

INSERT INTO table (teamid, team, etc, etc, etc) VALUES ('4', 'Team 4', '', '' ,'');

INSERT INTO table (teamid, team, etc, etc, etc) VALUES ('5', 'Team 5', '', '' ,'');

 

 

 

That's what I want it to do. That should be really simple. But I don't know what to do to get it to print out three of them. I can do one obviously with a post form. But from there, I get lost. And it's not always three rows. So how do I declare that?

 

Please help me. ^^;

Link to comment
Share on other sites

Well the big challenge here is knowing how you can create an array from normal fields. To create an array simply add [] to the name field identifier and add it for every field that is part of the array, like so:

 

<input type="checkbox" name="teams[]" id="teams" value="1" />
<input type="checkbox" name="teams[]" id="teams" value="2" />
<input type="checkbox" name="teams[]" id="teams" value="3" />
<input type="checkbox" name="teams[]" id="teams" value="4" />
<input type="checkbox" name="teams[]" id="teams" value="5" />

 

In php you threat it like a normal array:

 

<?php
print_r($_POST['teams']);
?>

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.