Help me please to figure out a logical solution to make such player list working
I have an array filled with data
player_number player_name
-------------|-------
1 | player1
2 | player2
3 | player3
6 | player6
8 | player8
12 | player12
-------------|-------
So as you see some numbers may be missed but max player_number
is always 50 so the question is how do I show all 50 fields though missing numbers also have to be shown but filled with "-" on its field
my logical problem is that my_array[$i] has it like 1 to 6(with list shown above) so my for() cycle just cant run it like that my_array[$i] == player_number
i want to have it shown like that on the page
1 | player1
2 | player2
3 | player3
4 | -
5 | -
6 | player6
7 | -
8 | player8
9 | -
10 | -
11 | -
12 | player12
-------------|-------
edit:
Its ok when I use the code provided but when I try to implement it with mine the logic fails
HowIGrabMyData() {
$query = $this->db->query($sql); // "SELECT * from `players` etc...
$output = array();
foreach ( $query->rows as $result ) {
$output[] = array(
'player_number' => $result['player_number'],
'player_name' => $result['player_nick']
);
}
return $output;
}
$players = HowIGrabMyData();
<?php for($i=1; $i <= 50; $i++){ // loop for 50 times
$player_name = "-";
if(isset($players[$i]['player_name'])){ // if the player name is set, use it
$player_name = $players[$i]['player_name'];
}
echo $i. " | ".$player_name."<br>";
}
It still shows like 1 to 6 rows in one line and not the way I want it with blank ones all over 50 fields I still miss main logic...