Jump to content

Organize my array


doc1355
Go to solution Solved by doc1355,

Recommended Posts

I'm working on a code for my WordPress and need to organize my array so that I can use the data for output in a table. 

In my WP, I have custom posts (called match) that has custom fields (user1, user2, s1p1, s1p2, s2p1, s2p2, s3p1, s3p2). 

Here is my script:

  $match_query = new WP_Query( $match_args );

  // If the query is empty, then don't do anything. Otherwise start the loop
  if ( $match_query->have_posts() ) {

    // Start the loop 
    while ( $match_query->have_posts() ) {
      $match_query->the_post();
      $match_id = get_the_ID(); // Get the ID of each Match post in this event.

      $related_user_1 = get_post_meta( $match_id, 'related_user_1' );
      $related_user_2 = get_post_meta( $match_id, 'related_user_2' );

      $set_1_player_1 = get_post_meta( $match_id, 'set_1_player_1' );
      $set_1_player_2 = get_post_meta( $match_id, 'set_1_player_2' );

      $set_2_player_1 = get_post_meta( $match_id, 'set_2_player_1' );
      $set_2_player_2 = get_post_meta( $match_id, 'set_2_player_2' );

      $set_3_player_1 = get_post_meta( $match_id, 'set_3_player_1' );
      $set_3_player_2 = get_post_meta( $match_id, 'set_3_player_2' );

      $pair_id[] = array(
        $related_user_1[ 0 ][ 'ID' ] => array(
            'u2' => $related_user_2[ 0 ][ 'ID' ],
            's1p1' => $set_1_player_1,
            's1p2' => $set_1_player_2,
            's2p1' => $set_2_player_1,
            's2p2' => $set_2_player_2,
            's3p1' => $set_3_player_1,
            's3p2' => $set_3_player_2,
        ),
      );
    }
  } else {
    // No posts Found. 
    echo 'No Matches Found.';
  }
  wp_reset_postdata();

My script is pulling all the data correctly and generating the following array: 

Array
(
    [0] => Array
        (
            [6] => Array
                (
                    [u2] => 4
                    [s1p1] => Array
                        (
                        )

                    [s1p2] => Array
                        (
                        )

                    [s2p1] => Array
                        (
                        )

                    [s2p2] => Array
                        (
                        )

                    [s3p1] => Array
                        (
                        )

                    [s3p2] => Array
                        (
                        )

                )

        )

    [1] => Array
        (
            [6] => Array
                (
                    [u2] => 3
                    [s1p1] => Array
                        (
                        )

                    [s1p2] => Array
                        (
                        )

                    [s2p1] => Array
                        (
                        )

                    [s2p2] => Array
                        (
                        )

                    [s3p1] => Array
                        (
                        )

                    [s3p2] => Array
                        (
                        )

                )

        )

    [2] => Array
        (
            [3] => Array
                (
                    [u2] => 4
                    [s1p1] => Array
                        (
                        )

                    [s1p2] => Array
                        (
                        )

                    [s2p1] => Array
                        (
                        )

                    [s2p2] => Array
                        (
                        )

                    [s3p1] => Array
                        (
                        )

                    [s3p2] => Array
                        (
                        )

                )

        )

    [3] => Array
        (
            [3] => Array
                (
                    [u2] => 11
                    [s1p1] => Array
                        (
                        )

                    [s1p2] => Array
                        (
                        )

                    [s2p1] => Array
                        (
                        )

                    [s2p2] => Array
                        (
                        )

                    [s3p1] => Array
                        (
                        )

                    [s3p2] => Array
                        (
                        )

                )

        )

    [4] => Array
        (
            [3] => Array
                (
                    [u2] => 11
                    [s1p1] => Array
                        (
                        )

                    [s1p2] => Array
                        (
                        )

                    [s2p1] => Array
                        (
                        )

                    [s2p2] => Array
                        (
                        )

                    [s3p1] => Array
                        (
                        )

                    [s3p2] => Array
                        (
                        )

                )

        )

    [5] => Array
        (
            [3] => Array
                (
                    [u2] => 4
                    [s1p1] => Array
                        (
                        )

                    [s1p2] => Array
                        (
                        )

                    [s2p1] => Array
                        (
                        )

                    [s2p2] => Array
                        (
                        )

                    [s3p1] => Array
                        (
                        )

                    [s3p2] => Array
                        (
                        )

                )

        )

    [6] => Array
        (
            [4] => Array
                (
                    [u2] => 11
                    [s1p1] => Array
                        (
                        )

                    [s1p2] => Array
                        (
                        )

                    [s2p1] => Array
                        (
                        )

                    [s2p2] => Array
                        (
                        )

                    [s3p1] => Array
                        (
                        )

                    [s3p2] => Array
                        (
                        )

                )

        )

    [7] => Array
        (
            [4] => Array
                (
                    [u2] => 11
                    [s1p1] => Array
                        (
                            [0] => 11
                        )

                    [s1p2] => Array
                        (
                            [0] => 12
                        )

                    [s2p1] => Array
                        (
                        )

                    [s2p2] => Array
                        (
                        )

                    [s3p1] => Array
                        (
                        )

                    [s3p2] => Array
                        (
                        )

                )

        )

    [8] => Array
        (
            [6] => Array
                (
                    [u2] => 3
                    [s1p1] => Array
                        (
                        )

                    [s1p2] => Array
                        (
                        )

                    [s2p1] => Array
                        (
                        )

                    [s2p2] => Array
                        (
                        )

                    [s3p1] => Array
                        (
                        )

                    [s3p2] => Array
                        (
                        )

                )

        )

    [9] => Array
        (
            [6] => Array
                (
                    [u2] => 4
                    [s1p1] => Array
                        (
                        )

                    [s1p2] => Array
                        (
                        )

                    [s2p1] => Array
                        (
                        )

                    [s2p2] => Array
                        (
                        )

                    [s3p1] => Array
                        (
                        )

                    [s3p2] => Array
                        (
                        )

                )

        )

    [10] => Array
        (
            [6] => Array
                (
                    [u2] => 11
                    [s1p1] => Array
                        (
                        )

                    [s1p2] => Array
                        (
                        )

                    [s2p1] => Array
                        (
                        )

                    [s2p2] => Array
                        (
                        )

                    [s3p1] => Array
                        (
                        )

                    [s3p2] => Array
                        (
                        )

                )

        )

    [11] => Array
        (
            [6] => Array
                (
                    [u2] => 11
                    [s1p1] => Array
                        (
                        )

                    [s1p2] => Array
                        (
                        )

                    [s2p1] => Array
                        (
                        )

                    [s2p2] => Array
                        (
                        )

                    [s3p1] => Array
                        (
                        )

                    [s3p2] => Array
                        (
                        )

                )

        )

)

The issue is that I need to setup a table to have one unique user in the first column, with all the data associated with that in the following column in front of it. Like the attached image

table.jpg.6dee102699ea1b8aab3f4086040f8322.jpg

 

I am not sure how I can generate the above table with my current array and I don't know how to rearrange my array to do this. 

 

Thank you again for all the help. 

 

Link to comment
Share on other sites

2 minutes ago, gw1500se said:

If I understand correctly, you loop on the outer sorted array. The within that loop you sort each inner array and loop on that to output the table.

I'm not looking to sort the data. I can show the data in any order and that's OK. I apologize if I didn't explain better.

The final table is to show a an entire sport event results. . The first column on the left, is each player in that event [shown as number]. In front of each player, each cell, will represent one match, and each have data associated with that match (opponent name [shown as ID], match scores[s1-p1, ..... ] ). 

So, when player 4 plays a match with player 6, that match data will be shown in two boxes, once in front of player 4 and once in front of player 6. 

@Barand helped me to create a table for the players and that is working fine 

 The problem that I have is to add the match results to each cell. That's what I'm trying to do. 

I hope this explains better. 

 

Thank you again for your time. 

 

Link to comment
Share on other sites

15 minutes ago, gw1500se said:

Are you asking how to create a table within a cell of an outer table?

No, I'm asking how to put all the data from one match inside one cell using a loop. 

The following code works to create the table as in the previous thread: 

  foreach ( $user as $u1 => $u2s ) {
    echo '<tr><td>' . $u1 . '</td>';
    foreach ( $u2s as $x ) {
      echo '<td>' . $x . '</td>';
    }
    echo '</tr>';
  }

 

What I need is on line #4 where I echo $x to show the opponents name, I also want to show the match results (s1p1, s2p2, ..... ) 

 

 

Link to comment
Share on other sites

Too many ambiguities for me.

Where you say you want image.png.b08bfe6d1e07035ebcc378d1fb3129c6.pngoutputting, I assume s1p1 is the value from the subarray with that key. Am I correct?

If I am, do you want

  • s1p1 minus s1p2 or
  • do you want them displaying as game results (eg 10 - 12)?

The values for s1p1 etc are all arrays which suggests there could be multiple values.

  • If there are multiple values, how should they be procesed?
  • If there aren't multiple values (as your sample only ever shows 0 or 1 values) why is it an array?

Finally, in your topic you posted earlier I showed you the technique to get to the output. This is only an extension of that, so what exactly are you having a problem with?

 

PS

If you are posting a large array with the expectation of some else testing with it, use var_export($array), not print_r()

Edited by Barand
PS
Link to comment
Share on other sites

1 minute ago, Barand said:

Too many ambiguities for me.

Where you say you want image.png.b08bfe6d1e07035ebcc378d1fb3129c6.pngoutputting, I assume s1p1 is the value from the subarray with that key. Am I correct?

If I am, do you want

  • s1p1 minus s1p2 or
  • do you want them displaying as game results (eg 10 - 12)?

The values for s1p1 etc are all arrays which suggests there could be multiple values.

  • If there are multiple values, how should they be procesed?
  • If there aren't multiple values (as your sample only ever shows 0 or 1 values) why is it an array?

Finally, in your topic you posted earlier I showed you the technique to get to the output. This is only an extension of that, so what exactly are you having a problem with?

Yes, S1P1 means Set1-Player1. It will show the result of the first set for the Player1 (which is the player in the first column).

S1P2 is the result of Set1 for Player2. 

S2P1 is the result of Second set for player 1
S2P2 is the result of Second set for player 2. 

There are maximum of three sets per match. If there is no results it will show "-" until the result is posted. 

 

This is the how the final result should look like. 

Table2.jpg.b0047e2c15a0fc3244832fbdd943c90d.jpg

I color coded the matches that are the same. For example, Kim and Tom played two matches. The result of first match are in the yellow box and the second match in the purple box. 

First match scores were as
Tom 2 - Kim 6
Tom 1 - Kim 6

Second Match Scores
Tom 6 - Kim 3
Tom 7 - Kim 6

They did not play the third set.

Other scenarios in the table: 
- Mike and Kim only played once. They haven't played the second match yet. That's why they both have one box without match results (light green)
- John and Tom played twice (Green and light blue). One match, they played three sets (Green) and one they played two sets (light blue). 

Also, the scores in each box are in specific order. The first score is for the player in the first column, the second score is for the player inside the cell. 

I hope this explains better.  

Link to comment
Share on other sites

5 minutes ago, Barand said:

You don't explain why the scores are in arrays

image.png.a47fcf662033d379a61f013718a9a582.png

 

That's my problem with the code. I don't know how to fix or make the array so that I can use the data to generate the table. It does't have to be if you know a way to get the the table. Please feel free to change my code that I posted above to whatever you think it will work. 

Edited by doc1355
Link to comment
Share on other sites

You won't make it worse. Let me explain, 

The line 

get_post_meta( $match_id, 'related_user_1' )

 captures the user array for player 1. ( we need to add [ 0 ][ 'ID' ] to get the ID)

change 'related_user_1' and you will get other results from the match: 

related_user_2 will be player 2
set_1_player_1 is the value for first set, player 1. This is not an array. It is just the value itself. 
set_1_player_2 is the value for first set, player 2. This is not an array. It is just the value itself. 
and so on. 

All the above are running in a while() loop so that it captures all the results for the event. Each time this loop runs, it collects the data for one match, which should go into one cell in my table (except for the player 1 that goes to the first column). 

This part below ($pair_id .....) , is my attempt to create an array. This is where I need the help to setup appropriate array so that I can create my table. 

$pair_id[] = array(
        $related_user_1[ 0 ][ 'ID' ] => array(
            'u2' => $related_user_2[ 0 ][ 'ID' ],
            's1p1' => $set_1_player_1,
            's1p2' => $set_1_player_2,
            's2p1' => $set_2_player_1,
            's2p2' => $set_2_player_2,
            's3p1' => $set_3_player_1,
            's3p2' => $set_3_player_2,
        ),
      );

 

Edited by doc1355
Link to comment
Share on other sites

I created some dummy users, matches and results to make it easier to read the output. 

Here is the var_export for $pair_id. Please let me know if you need other information: 

array ( 0 => array ( 'Sam Bina' => array ( 'u2' => 'David Smith', 's1p1' => array ( ), 's1p2' => array ( ), 's2p1' => array ( ), 's2p2' => array ( ), 's3p1' => array ( ), 's3p2' => array ( ), ), ), 1 => array ( 'Sam Bina' => array ( 'u2' => 'Fred Thompson', 's1p1' => array ( ), 's1p2' => array ( ), 's2p1' => array ( ), 's2p2' => array ( ), 's3p1' => array ( ), 's3p2' => array ( ), ), ), 2 => array ( 'Fred Thompson' => array ( 'u2' => 'Frank Molino', 's1p1' => array ( ), 's1p2' => array ( ), 's2p1' => array ( ), 's2p2' => array ( ), 's3p1' => array ( ), 's3p2' => array ( ), ), ), 3 => array ( 'Frank Molino' => array ( 'u2' => 'David Smith', 's1p1' => array ( ), 's1p2' => array ( ), 's2p1' => array ( ), 's2p2' => array ( ), 's3p1' => array ( ), 's3p2' => array ( ), ), ), 4 => array ( 'Sam Bina' => array ( 'u2' => 'Fred Thompson', 's1p1' => array ( 0 => '6', ), 's1p2' => array ( 0 => '2', ), 's2p1' => array ( 0 => '3', ), 's2p2' => array ( 0 => '6', ), 's3p1' => array ( ), 's3p2' => array ( ), ), ), 5 => array ( 'Frank Molino' => array ( 'u2' => 'David Smith', 's1p1' => array ( 0 => '6', ), 's1p2' => array ( 0 => '1', ), 's2p1' => array ( 0 => '6', ), 's2p2' => array ( 0 => '2', ), 's3p1' => array ( ), 's3p2' => array ( ), ), ), 6 => array ( 'Fred Thompson' => array ( 'u2' => 'Frank Molino', 's1p1' => array ( 0 => '6', ), 's1p2' => array ( 0 => '2', ), 's2p1' => array ( 0 => '7', ), 's2p2' => array ( 0 => '5', ), 's3p1' => array ( ), 's3p2' => array ( ), ), ), 7 => array ( 'Fred Thompson' => array ( 'u2' => 'David Smith', 's1p1' => array ( 0 => '5', ), 's1p2' => array ( 0 => '7', ), 's2p1' => array ( 0 => '7', ), 's2p2' => array ( 0 => '5', ), 's3p1' => array ( 0 => '6', ), 's3p2' => array ( 0 => '3', ), ), ), 8 => array ( 'Fred Thompson' => array ( 'u2' => 'David Smith', 's1p1' => array ( 0 => '6', ), 's1p2' => array ( 0 => '2', ), 's2p1' => array ( 0 => '6', ), 's2p2' => array ( 0 => '1', ), 's3p1' => array ( ), 's3p2' => array ( ), ), ), 9 => array ( 'Sam Bina' => array ( 'u2' => 'Frank Molino', 's1p1' => array ( 0 => '1', ), 's1p2' => array ( 0 => '6', ), 's2p1' => array ( 0 => '2', ), 's2p2' => array ( 0 => '6', ), 's3p1' => array ( ), 's3p2' => array ( ), ), ), 10 => array ( 'Sam Bina' => array ( 'u2' => 'David Smith', 's1p1' => array ( 0 => '3', ), 's1p2' => array ( 0 => '6', ), 's2p1' => array ( 0 => '6', ), 's2p2' => array ( 0 => '3', ), 's3p1' => array ( 0 => '6', ), 's3p2' => array ( 0 => '2', ), ), ), 11 => array ( 'Sam Bina' => array ( 'u2' => 'Frank Molino', 's1p1' => array ( 0 => '6', ), 's1p2' => array ( 0 => '4', ), 's2p1' => array ( 0 => '6', ), 's2p2' => array ( 0 => '4', ), 's3p1' => array ( ), 's3p2' => array ( ), ), ), )

 

Link to comment
Share on other sites

Ok, let's try one more time. 

I changed my array script to this: 

      $match[] = array(
        'p1' => $related_user_1[ 0 ][ 'ID' ],
        'p2' => $related_user_2[ 0 ][ 'ID' ],
        's1p1' => $set_1_player_1,
        's1p2' => $set_1_player_2,
        's2p1' => $set_2_player_1,
        's2p2' => $set_2_player_2,
        's3p1' => $set_3_player_1,
        's3p2' => $set_3_player_2,
      );

This will give me the following var_export: 

array ( 0 => array ( 'p1' => 'Sam Bina', 'p2' => 'David Smith', 's1p1' => array ( ), 's1p2' => array ( ), 's2p1' => array ( ), 's2p2' => array ( ), 's3p1' => array ( ), 's3p2' => array ( ), ), 1 => array ( 'p1' => 'Sam Bina', 'p2' => 'Fred Thompson', 's1p1' => array ( ), 's1p2' => array ( ), 's2p1' => array ( ), 's2p2' => array ( ), 's3p1' => array ( ), 's3p2' => array ( ), ), 2 => array ( 'p1' => 'Fred Thompson', 'p2' => 'Frank Molino', 's1p1' => array ( ), 's1p2' => array ( ), 's2p1' => array ( ), 's2p2' => array ( ), 's3p1' => array ( ), 's3p2' => array ( ), ), 3 => array ( 'p1' => 'Frank Molino', 'p2' => 'David Smith', 's1p1' => array ( ), 's1p2' => array ( ), 's2p1' => array ( ), 's2p2' => array ( ), 's3p1' => array ( ), 's3p2' => array ( ), ), 4 => array ( 'p1' => 'Sam Bina', 'p2' => 'Fred Thompson', 's1p1' => array ( 0 => '6', ), 's1p2' => array ( 0 => '2', ), 's2p1' => array ( 0 => '3', ), 's2p2' => array ( 0 => '6', ), 's3p1' => array ( ), 's3p2' => array ( ), ), 5 => array ( 'p1' => 'Frank Molino', 'p2' => 'David Smith', 's1p1' => array ( 0 => '6', ), 's1p2' => array ( 0 => '1', ), 's2p1' => array ( 0 => '6', ), 's2p2' => array ( 0 => '2', ), 's3p1' => array ( ), 's3p2' => array ( ), ), 6 => array ( 'p1' => 'Fred Thompson', 'p2' => 'Frank Molino', 's1p1' => array ( 0 => '6', ), 's1p2' => array ( 0 => '2', ), 's2p1' => array ( 0 => '7', ), 's2p2' => array ( 0 => '5', ), 's3p1' => array ( ), 's3p2' => array ( ), ), 7 => array ( 'p1' => 'Fred Thompson', 'p2' => 'David Smith', 's1p1' => array ( 0 => '5', ), 's1p2' => array ( 0 => '7', ), 's2p1' => array ( 0 => '7', ), 's2p2' => array ( 0 => '5', ), 's3p1' => array ( 0 => '6', ), 's3p2' => array ( 0 => '3', ), ), 8 => array ( 'p1' => 'Fred Thompson', 'p2' => 'David Smith', 's1p1' => array ( 0 => '6', ), 's1p2' => array ( 0 => '2', ), 's2p1' => array ( 0 => '6', ), 's2p2' => array ( 0 => '1', ), 's3p1' => array ( ), 's3p2' => array ( ), ), 9 => array ( 'p1' => 'Sam Bina', 'p2' => 'Frank Molino', 's1p1' => array ( 0 => '1', ), 's1p2' => array ( 0 => '6', ), 's2p1' => array ( 0 => '2', ), 's2p2' => array ( 0 => '6', ), 's3p1' => array ( ), 's3p2' => array ( ), ), 10 => array ( 'p1' => 'Sam Bina', 'p2' => 'David Smith', 's1p1' => array ( 0 => '3', ), 's1p2' => array ( 0 => '6', ), 's2p1' => array ( 0 => '6', ), 's2p2' => array ( 0 => '3', ), 's3p1' => array ( 0 => '6', ), 's3p2' => array ( 0 => '2', ), ), 11 => array ( 'p1' => 'Sam Bina', 'p2' => 'Frank Molino', 's1p1' => array ( 0 => '6', ), 's1p2' => array ( 0 => '4', ), 's2p1' => array ( 0 => '6', ), 's2p2' => array ( 0 => '4', ), 's3p1' => array ( ), 's3p2' => array ( ), ), )

Can this be used to create the table? 

Link to comment
Share on other sites

Getting better!.

Change to

$match[] = array(
        'p1' => $related_user_1[ 0 ][ 'ID' ],
        'p2' => $related_user_2[ 0 ][ 'ID' ],
        's1p1' => $set_1_player_1[0] ?? '',
        's1p2' => $set_1_player_2[0] ?? '',
        's2p1' => $set_2_player_1[0] ?? '',
        's2p2' => $set_2_player_2[0] ?? '',
        's3p1' => $set_3_player_1[0] ?? '',
        's3p2' => $set_3_player_2[0] ?? '',
      );

That should change the array from

    [11] => Array
        (
            [p1] => Sam Bina
            [p2] => Frank Molino
            [s1p1] => Array
                (
                    [0] => 6
                )

            [s1p2] => Array
                (
                    [0] => 4
                )

            [s2p1] => Array
                (
                    [0] => 6
                )

            [s2p2] => Array
                (
                    [0] => 4
                )

            [s3p1] => Array
                (
                )

            [s3p2] => Array
                (
                )

        )

to

    [11] => Array
        (
            [p1] => Sam Bina
            [p2] => Frank Molino
            [s1p1] => 6
            [s1p2] => 4
            [s2p1] => 6
            [s2p2] => 4
            [s3p1] => 
            [s3p2] =>

        )

 

  • Like 1
Link to comment
Share on other sites

  • Solution

@Barand Thanks to your last suggestion, I was able to make the table the way I wanted. 

Here is what I did: 

I add all the players to an array. I created an array to collect all the players ID, and a separate array to collect all the data for each match: 

    while ( $match_query->have_posts() ) {
      $match_query->the_post();
      $match_id = get_the_ID(); // Get the ID of each Match post in this event.

      $related_user_1 = get_post_meta( $match_id, 'related_user_1' );
      $related_user_2 = get_post_meta( $match_id, 'related_user_2' );

      $set_1_player_1 = get_post_meta( $match_id, 'set_1_player_1' );
      $set_1_player_2 = get_post_meta( $match_id, 'set_1_player_2' );

      $set_2_player_1 = get_post_meta( $match_id, 'set_2_player_1' );
      $set_2_player_2 = get_post_meta( $match_id, 'set_2_player_2' );

      $set_3_player_1 = get_post_meta( $match_id, 'set_3_player_1' );
      $set_3_player_2 = get_post_meta( $match_id, 'set_3_player_2' );

      $all_players[] = $related_user_1[ 0 ][ ' ID' ];
      $all_players[] = $related_user_2[ 0 ][ ' ID' ];

      $match_array[] = array(
        'p1' => $related_user_1[ 0 ][ ' ID' ],
        'p2' => $related_user_2[ 0 ][ ' ID' ],
        's1p1' => $set_1_player_1[ 0 ] ?? '',
        's1p2' => $set_1_player_2[ 0 ] ?? '',
        's2p1' => $set_2_player_1[ 0 ] ?? '',
        's2p2' => $set_2_player_2[ 0 ] ?? '',
        's3p1' => $set_3_player_1[ 0 ] ?? '',
        's3p2' => $set_3_player_2[ 0 ] ?? '',
      );

    }

Then I removed the duplicate players from the player array: 

$cleaned_player_id = array_unique( $all_players );

Now here comes the table: First I enter the unique player from the cleaned list into the first column. Then I loop through match data with if statement and show the results accordingly. 

  $output = '<table class="uk-table uk-table-striped uk-table-small"><tbody>';
  foreach ( $cleaned_player_id as $c ) {
    $output .= '<tr><td>' . $c . '</td>';
    foreach ( $match_array as $m ) {
      if ( $m[ 'p1' ] == $c ) {
        $output .= '<td>' . $m[ 'p2' ] . '<br>' . $m[ 's1p1' ] . '-' . $m[ 's1p2' ] . ', ' . $m[ 's2p1' ] . '-' . $m[ 's2p2' ] . ', ' . $m[ 's3p1' ] . '-' . $m[ 's3p2' ] . '</td>';
      } elseif ( $m[ 'p2' ] == $c ) {
        $output .= '<td>' . $m[ 'p1' ] . '<br>' . $m[ 's1p2' ] . '-' . $m[ 's1p1' ] . ', ' . $m[ 's2p2' ] . '-' . $m[ 's2p1' ] . ', ' . $m[ 's3p2' ] . '-' . $m[ 's3p1' ] . '</td>';
      }
    }
    $output .= '</tr></tbody></table>';
  }

Please let me know your thoughts?

Link to comment
Share on other sites

Correction the closing tag for the tbody and table should be outside the the last foreach loop. 

  $output = '<table class="uk-table uk-table-striped uk-table-small"><tbody>';
  foreach ( $cleaned_player_id as $c ) {
    $output .= '<tr><td>' . $c . '</td>';
    foreach ( $match_array as $m ) {
      if ( $m[ 'p1' ] == $c ) {
        $output .= '<td>' . $m[ 'p2' ] . '<br>' . $m[ 's1p1' ] . '-' . $m[ 's1p2' ] . ', ' . $m[ 's2p1' ] . '-' . $m[ 's2p2' ] . ', ' . $m[ 's3p1' ] . '-' . $m[ 's3p2' ] . '</td>';
      } elseif ( $m[ 'p2' ] == $c ) {
        $output .= '<td>' . $m[ 'p1' ] . '<br>' . $m[ 's1p2' ] . '-' . $m[ 's1p1' ] . ', ' . $m[ 's2p2' ] . '-' . $m[ 's2p1' ] . ', ' . $m[ 's3p2' ] . '-' . $m[ 's3p1' ] . '</td>';
      }
    }
    $output .= '</tr>';
  }
  $output .= '</tbody></table>';

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.