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
https://forums.phpfreaks.com/topic/156380-complicating-question/
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']);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.