Skip to content
Advertisement

How can I make this list working with blank fields showing in it?

Help me please to figure out a logical solution to make such player list working

I have an array filled with data

JavaScript

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

JavaScript

edit:

Its ok when I use the code provided but when I try to implement it with mine the logic fails

JavaScript

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…

Advertisement

Answer

NEW ANSWER.

I have updated my answer with your new array format.

This time we create an array with 50 indexes all set to ‘-‘. we then go over the out put array and put the player names in the correct spot in the array that has the 50 indexes. Finally we go over the 50 indexes and print them to the screen.

Here is the code:

JavaScript

OLD ANSWER

You have to create a for loop that runs 50 times, check to see if there is a value for the index in the array and if there is use the name at that index. Otherwise it will just use – as the player name.

Try this:

JavaScript

Check out isset() function.

you could also use array_key_exists() instead of isset(). Like this:

JavaScript

Also have a look at isset() vs array_key_exists(). Handy to know the difference between the two.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement