I'll try to explain this as best I can.
I'm making a page for a world war 2 game I play (wwiionline.com) that will organize missions for my squad. It was going pretty smoothly until now. I'm trying to fill in a command structure.
A rough guideline of a command structure is this:
...
Battalion - Made up of 4 companies
Company - Made up of 3 platoons
Platoon - Made up of 3 squads
Squad - Made up of 10 soldiers
I have it so the mission creator can choose how many squads there are. Therefore if he picks 9 squads the command structure should set up like this:
1 Battalion
1 Company
1 Platoon
1 Squad
2 Squad
3 Squad
2 Platoon
1 Squad
2 Squad
3 Squad
3 Platoon
1 Squad
2 Squad
3 Squad
I also have it where the mission creator can choose how many people can be in each squad. So if he picks 7 it needs to come out like this:
1 Battalion
1 Company
1 Platoon
1 Squad
Soldier 1
Soldier 2
Soldier 3
Soldier 4
Soldier 5
Soldier 6
Soldier 7
2 Squad
Soldier 1
Soldier 2
Soldier 3
Soldier 4
Soldier 5
Soldier 6
Soldier 7
3 Squad
Soldier 1
Soldier 2
Soldier 3
Soldier 4
Soldier 5
Soldier 6
Soldier 7
If he picks 3 squads, with 7 people in each, but only 4 people have signed up, and for different squads; it should look like this:
1 Battalion
1 Company
1 Platoon
1 Squad
Soldier 1
Soldier 2
2 Squad
3 Squad
Soldier 1
Soldier 2
I HAVE TO put it all in an array to be able to print it out on the page.
This is the code I currently have:
$squadnames = array();
$i=1;
$query = "SELECT * FROM phpbb_operations_users WHERE operation_id = $op_id";
$result = $db->sql_query($query) or die(print_r($db->sql_error(),true));
while($row=mysql_fetch_array($result)){
for ($o=1; $o <= $squads; $o++)
if ($row[5] == $o)
{
$squadnames[$o][$i]=$row[2]; //puts value in here
}
$i++;
}
//$row[5] is the squad that the user selected. $i is the amount of people signed up. $row[2] is the nickname of the user. So the multidimension array is: $squadnames[squadselection][elementinsquad] = username.
for ($i=0; $i <= $numbers; $i++)
{
for($o=1; $o <= $squads; $o++) {
if ($squadnames[$o][$i] != NULL)
{
$template->assign_block_vars('opinfo', array(
'OP_REGISTERED' => $squadnames[$o][$i])
);
}
}
}
//This just sends the multidimension array of names to the page. It does not have any sort of command structure. Just a list of nicknames from users who have signed up. $numbers is the amount of people signed up. $squads is the number of squads the mission creator chose.
//All of this code works
I'm thinking the best way to do this is by creating the structure as I fill in the names. I just can't think of how to do it. If someone could get me started, I could probably figure the rest out.
for ($i=0; $i <= $numbers; $i++)
{
for($o=1; $o <= $squads; $o++) {
$structure[$o] = "Battalian $i."; //every 4 companies put this in the array
$structure[$o] = "Company $i."; //every 3 platoons put this in the array
$structure[$o] = "Platoon $i."; //every 3 squads put this in the array
$structure[$o] = "Squad $i."; //every squad put this in the array
$structure[$o] = $squadnames[$o][$i] //print out the usernames of the people in the squad. Probably using a for loop or something.
// The $o in $structure[$o] would of course have some sort of arithmetic. They won't (can't) be all the same. I just don't know what I need.
}
}
I think I'm going braindead. If you have any questions or need more data, please just ask.