require_once("public.php");
function getTotals($part_min, $part_max){
global $db;
$session_id = weight_session_getCurrentSessionId();
$sql = "
SELECT
CONCAT_WS(' - ', c.name, c.team_name) name,
c.start_weight,
sum(sw.weight),
(
ifnull((select sum(weight) from session_weight where session_id = $session_id and competitor_id = c.id and direction = 'lost'), 0) -
ifnull((select sum(weight) from session_weight where session_id = $session_id and competitor_id = c.id and direction = 'gained'), 0)
) lost,
(
(100 * (
(
ifnull((select sum(weight) from session_weight where session_id = $session_id and competitor_id = c.id and direction = 'lost'), 0) -
ifnull((select sum(weight) from session_weight where session_id = $session_id and competitor_id = c.id and direction = 'gained'), 0)
)
) / c.start_weight)
) percent
FROM
session_weight sw, competitor c
WHERE
sw.competitor_id = c.id
AND c.session_id = $session_id
AND participants >= $part_min
AND participants <= $part_max
GROUP BY competitor_id
ORDER BY percent DESC
";
return $db->getAllRows($sql);
}
header('Cache-Control: no-cache');
header('Pragma: no-cache');
?>
10 and Under Participating EmployeesCompany
Total % Weight Lost
Total Pounds Lost
$rows = getTotals(0, 10) ?>
foreach($rows as $row): ?>
= HTML_escapeHTML($row["name"]) ?>
= number_format($row["percent"], 2) ?>%
= number_format($row["lost"], 2) ?>
endforeach; ?>
11 - 29 participating EmployeesCompany
Total % Weight Lost
Total Pounds Lost
$rows = getTotals(11, 29) ?>
foreach($rows as $row): ?>
= HTML_escapeHTML($row["name"]) ?>
= number_format($row["percent"], 2) ?>%
= number_format($row["lost"], 2) ?>
endforeach; ?>
30 - 59 Participating EmployeesCompany
Total % Weight Lost
Total Pounds Lost
$rows = getTotals(30, 59) ?>
foreach($rows as $row): ?>
= HTML_escapeHTML($row["name"]) ?>
= number_format($row["percent"], 2) ?>%
= number_format($row["lost"], 2) ?>
endforeach; ?>
60+ Participating EmployeesCompany
Total % Weight Lost
Total Pounds Lost
$rows = getTotals(60, 5000) ?>
foreach($rows as $row): ?>