I am working on a project and I came across something that I just don’t know how to solve. I have 3 tables in a Firebird database :
|TEAM | ACTIVITY|
|-----|---------|
| 1 | JUMPING |
Team 1 – jumping
| PLAYER | TEAM |
|--------|------|
| 10 | 1 |
| 15 | 1 |
The player 10 and 15 are in Team 1
And the last table is this one :
| PLAYER_ID | PLAYER_NAME | AGE | HEIGHT |
|-----------|-------------|-----|--------|
| 10 | Alex | 25 | 175 |
| 15 | Andrew | 17 | 187 |
Player 10 -> Alex -> age 25 -> height 175
Player 15 -> Andrew -> age 17 -> height 187
My main goal is to make an HTML page with a textbox, in the textbox I will type the Team number (in this case I will type 1) and it will show me who is in the team with his qualities (age and height).
$teamPlayers= "SELECT PLAYER_ID
FROM TEAM
WHERE TEAM= $teamNumber;";
( keep in mind, $teamNumber is the value introduced by the user in the HTML textbox )
$y = ibase_query($dbConnect, $teamPlayers);
while ($row1 = ibase_fetch_object($y)) {
$array1 = get_object_vars($row1);
echo $array1["PLAYER_ID"];}
This program outputs 1015 which is fine, means the program is working, but I need to know if there is other way of selecting the players of the team, since this one basically joins their IDs together, and I need them separately so I can assign their IDs to separate variables.
Advertisement
Answer
I believe you need to iterate the array you get from SQL database. Ex.
$teamPlayers= "SELECT PLAYER_ID
FROM TEAM
WHERE TEAM= $teamNumber;"
$playerIDArray = array();
$ct = 0;
foreach ($teamPlayers as $players) {
$ct += 1;
$playerIDArray[$ct] = $players["PLAYER_ID"]
}