region.php
Why total mileage is listed as 0:
$activeTotalMileage = $row['totalActiveMileage'];
when
$row = tm_fetch_user_row_with_rank($activeClinchedRes, 'activeClinched');
when there is no actual user row to fetch in $activeClinchedRes.
Using a separate query to get total mileage before the main query that gets our results, similar to what's done elsewhere on the site, should clear this up.
Why Distance Traveled Rank is n out of n travelers:
In tm_fetch_user_row_with_rank, the while loop is executed 8 times, once for each traveler. $rank is set to $nextRank for values of 1 to 8 inclusive.
Why Routes Traveled/Clinched Rank is n+1 out of n travelers:
If I query
SELECT traveler, SUM(cr.clinched) AS clinched, ROUND(sum(cr.clinched) / 112 * 100, 2) as clinchedPct FROM routes AS r LEFT JOIN clinchedRoutes AS cr ON cr.route = r.root LEFT JOIN systems ON r.systemName = systems.systemName WHERE (r.region = 'ESP-CT' AND systems.level = 'active') GROUP BY traveler ORDER BY clinched DESC;
I get an extra 9th row in my results where all fields are NULL, allowing for one more iteration of the while loop in tm_fetch_user_row_with_rank.
Changing the first LEFT JOIN to a RIGHT JOIN eliminates this extra row. (Do we want to do this?)
Technically, I am in a 238-way tie for 9th place here, along with everyone else traveling 0 routes. Do we prefer to present this information that way, or as N/A as suggested in the OP?