global $wpdb; // 1. Fetch all top 100 players ordered by rank // Replace 'nhl_player_stats' with your actual table name $table_name = 'nhl_player_stats'; $top_100 = $wpdb->get_results( "SELECT * FROM {$table_name} WHERE rank <= 100 ORDER BY rank ASC" ); if ( ! $top_100 ) { return '

No player data found.

'; } // Map the top 100 by rank for quick O(1) lookups $rank_map = []; foreach ( $top_100 as $player ) { $rank_map[intval( $player->rank )] = $player; } // 2. Identify active players within the top 100 and determine their windows (±3) $included_ranks = []; foreach ( $top_100 as $player ) { // Adjust this condition based on how you flag active players in your database if ( isset( $player->is_active ) && $player->is_active == 1 ) { $target_rank = intval( $player->rank ); // Define the window (3 ahead, 3 behind, bounded between 1 and 100) $start = max( 1, $target_rank - 3 ); $end = min( 100, $target_rank + 3 ); for ( $r = $start; $r <= $end; $r++ ) { $included_ranks[$r] = true; } } } // Sort the captured ranks ascending ksort( $included_ranks ); // 3. Build the final display list and check for gaps $players_to_display = []; foreach ( array_keys( $included_ranks ) as $rank ) { if ( isset( $rank_map[$rank] ) ) { $players_to_display[] = $rank_map[$rank]; } } // 4. Render the Output Table $output = '
'; $output .= ''; $output .= ''; $output .= ''; $prev_rank = null; foreach ( $players_to_display as $player ) { $current_rank = intval( $player->rank ); // If there's a gap greater than 1 between the previous rank and current rank, insert a separator row if ( $prev_rank !== null && $current_rank > ( $prev_rank + 1 ) ) { $output .= ''; } // Add a CSS class or highlight style if the player is active $is_active_class = ( isset( $player->is_active ) && $player->is_active == 1 ) ? ' active-target-player' : ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $prev_rank = $current_rank; } $output .= ''; $output .= '
RankPlayerTeamStats
• • •
' . esc_html( $player->rank ) . '' . esc_html( $player->player_name ) . '' . esc_html( $player->team_abbr ) . '' . esc_html( $player->points ?? '' ) . '
'; $output .= '
'; echo $output; PV29 – Activity – OutsideTheGarden Boards – Page 17
SEPTEMBER
«
Sun
19
Mon
20
Tue
21
Wed
22
Thu
23
Fri
24
Sat
25
»
PV29
PV29
Group: Registered
Joined: 2023-09-25
Team MVP
1
Follow
So glad that Sam got to finally see the Smith brothers on th...

In forum Where Smit Hits The Fan

2 years ago
Stars skate right up the middle with the puck, nobody touche...

In forum Where Smit Hits The Fan

2 years ago
Trade. Adam. Fox. I'm just so tired of watching this littl...

In forum Where Smit Hits The Fan

2 years ago
Rangers passing in the defensive zone is awful. Laffrenier...

In forum Where Smit Hits The Fan

2 years ago
Because they are afraid to get hit. Going to the middle rai...

In forum Where Smit Hits The Fan

2 years ago
As much as I like Rempe, I would take Olivier now in exchang...

In forum Where Smit Hits The Fan

2 years ago
Rempe suspended for 8 games

In forum Where Smit Hits The Fan

2 years ago
Perimeterjad and Sleepy Chris with another useless, invisibl...

In forum Where Smit Hits The Fan

2 years ago
2nd period reality check. Canes won virtually every board ...

In forum Where Smit Hits The Fan

2 years ago
Canes have come out, likely after getting their asses chewed...

In forum Where Smit Hits The Fan

2 years ago
Somebody drill that little turd Jarvis into the third row. ...

In forum Where Smit Hits The Fan

2 years ago
Great hit along the boards by a Ranger, while the Laundromat...

In forum Where Smit Hits The Fan

2 years ago
MacTavish

In forum Where Smit Hits The Fan

2 years ago
Rangers defense is backing in to the top of the circles. Th...

In forum Where Smit Hits The Fan

2 years ago
Sam the pacifist rooting for his boy Vesey. Rempe makes Sam...

In forum Where Smit Hits The Fan

2 years ago
Page 17 / 38