Jay, you mentioned you have only one table and then you made two tables. We should start there. How many
teams do you have? If only the two that you showed, then there is no need for two tables. If there are many
such as hundreds, then you would do better with two tables. In which case, use the join to get the names from
the indexed table of squads. Either way, you end up with a table of data that contains the team name, squad
name and members of the squads. Loosely in the form of TEAM, SQUAD, SOLDIERS and that basically means
that you just need to loop thru the results as I showed you and break where needed. There are many other
ways to handle this. I found a nice recursive version, but, it keeps running queries for the members. The way
I showed you should work. Here is a version combined with the code you posted. Without access to the DB,
not sure if it will work, but, test it and post the results…
First, think of the bullet code. Here is how it looks for the display using my own samples:
team name 1
squad name 1
- Soldiername1
- Soldiername2
squad name 2
- Soldiername3
- Soldiername4
team name 2
squad name 3
- Soldiername5
- Soldiername6
So, as you see, there are only two break points. First is teams and next squads. This makes sense, right? Your
code would have to check for each and display it as needed. Using the correct
tags
where they are needed. Here is a sample that might work for you. It is an improved version of the sample I
posted earlier. Try it and let us know if it works or not for you...
[php]
<?php
$result = mysqli_query($con,$query);
$num_rows = $result->num_rows;
if($num_rows > 0) {
$current_team="xyz";
$current_squad="xyz";
while(loop thru the results...) {
If($row[$team]!=$current_team) {
if($current_team!="xyz") echo ""; // close the previous team group
$current_team=$row[$team]; // set current team to new-current team
echo "
" . $row["team"]; // show team as top level...
}
If $row[$squad]!=$current_squad {
if($current_squad!="xyz") echo "
"; // close the previous squad group
$current_squad=$row[$squad]; // set current squad to new-squad team
echo "
" . $row["squad"]; // show squad as sub-level...
}
echo "- " . $row["Soldiername"] . "
"; // show Soldiername as lowest-level...
}
echo "
"; // close the entire group...
} else {
echo "No players online at this time!
";
}
?>
[/php]
Note that the "xyz" is just a name of a team that does not exist. It is used to start the loop with to know where
the code should end and display the correct ending of a group of data. This makes the end ( ) tag work.
The above is not tested as no DB connection. If it does not work for you, I can create a test array to use, but
it should work. It should create the needed bullet list for you. Let us know how it works for you...