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 14
APRIL
«
Fri
18
Sat
19
Sun
20
Mon
21
Tue
22
Wed
23
Thu
24
»
PV29
PV29
Group: Registered
Joined: 2023-09-25
Team MVP
1
Follow
Any line with Sam Carrick is always having a good game.

In forum Where Smit Hits The Fan

2 years ago
Joe M is gonna be the happiest guy at Sam’s retirement party...

In forum Where Smit Hits The Fan

2 years ago
WTF did he do to get benched? Serious question. No dumb pe...

In forum Where Smit Hits The Fan

2 years ago
Laff hasn’t scored since Sam had a decent wig, and instead o...

In forum Where Smit Hits The Fan

2 years ago
100%. Didn’t tolerate lazy crap. His Flyers team is still ...

In forum Where Smit Hits The Fan

2 years ago
Wow, Smith beats Velmfifibhaf for a shorty. Shoot more agai...

In forum Where Smit Hits The Fan

2 years ago
I enjoyed watching this team so much more when Torts was the...

In forum Where Smit Hits The Fan

2 years ago
No excuses, but the refs have missed 4 or 5 calls against Ut...

In forum Where Smit Hits The Fan

2 years ago
Rempe benched because the top 6 can’t generate offense.

In forum Where Smit Hits The Fan

2 years ago
Rangers can’t beat anyone 1-on-1 with the puck. Beating a d...

In forum Where Smit Hits The Fan

2 years ago
No Trocheck, no Chytil, the same passing bums for the 5 on 3...

In forum Where Smit Hits The Fan

2 years ago
Rangers getting a gift 5-on-3.

In forum Where Smit Hits The Fan

2 years ago
The MSG suits want a nifty skill team, not a bruising team l...

In forum Where Smit Hits The Fan

2 years ago
I spent too much time today watching videos of Uecker. Lite...

In forum Where Smit Hits The Fan

2 years ago
Mika and Miller covering nobody again. Just watching the pl...

In forum Where Smit Hits The Fan

2 years ago
Page 14 / 38