Jump to content

doc1355

Members
  • Posts

    67
  • Joined

  • Last visited

Everything posted by doc1355

  1. 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. 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.
  2. 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, ..... )
  3. 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.
  4. So, does it mean that it can't be done? !!!
  5. Thank you for your reply. With asort, I can only sort my array, but I won't be able to use a loop to create the table. The data in the table is repeated twice, once for each user in their own row.
  6. 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 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.
  7. Brilliant. This worked like a charm. Thank you so much.
  8. Thank you so much for your quick reply. This is a great help. By using the loop with the $new variable I can show half of the table (blue) only and not the other half (red). I know this is duplicate of the blue data . How can I show the second half (red) in my loop to make it a full table? 6: 4 3 3 4 11 11 4: 6 3 3 11 11 6 3: 6 4 11 11 4 6 11: 3 3 4 4 6 6
  9. I have an array as below: Array ( [0] => Array ( [u1] => 6 [u2] => 4 ) [1] => Array ( [u1] => 6 [u2] => 3 ) [2] => Array ( [u1] => 3 [u2] => 4 ) [3] => Array ( [u1] => 3 [u2] => 11 ) [4] => Array ( [u1] => 3 [u2] => 11 ) [5] => Array ( [u1] => 3 [u2] => 4 ) [6] => Array ( [u1] => 4 [u2] => 11 ) [7] => Array ( [u1] => 4 [u2] => 11 ) [8] => Array ( [u1] => 6 [u2] => 3 ) [9] => Array ( [u1] => 6 [u2] => 4 ) [10] => Array ( [u1] => 6 [u2] => 11 ) [11] => Array ( [u1] => 6 [u2] => 11 ) ) What I'm trying to achieve is to create a table as below: 6: 4 3 3 4 11 11 4: 6 3 3 11 11 6 3: 6 4 11 11 4 6 11: 3 3 4 4 6 6 Here is what is happening: It shows the first value of u1 (6) , then searches all the other arrays, if that value (6) exists, it shows the other value one at a time ( 4-3-3-4-11-11). Then starts new row, looks up the next value (which is not same as the first value and goes through the same process, until we have one row for all the unique numbers in the array, then stops. I'm not sure how I can setup my loop to do this and I appreciate any helps that anyone could offer. Thank you.
×
×
  • 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.