Jump to content

doc1355

Members
  • Posts

    67
  • Joined

  • Last visited

Community Answers

  1. doc1355's post in Get metadata from Stripe Session was marked as the answer   
    Thank you for your reply. But I was able to figure this out. 
    The metadata is associated with another object. I used the ID from this object to retrieve the second object and was able to retrieve the metadata there. 
    Thank you again for your help. 
  2. doc1355's post in Organize my array was marked as the answer   
    @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?
×
×
  • 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.