Leaderboard

[insert_php]

include(‘/websites/ma/manlyswimclub.org.au/wp-includes/variables.inc’);

if ($_POST[‘submitted’] == “true”) {
$result = $_POST[‘field’];
$result_explode = explode(‘|’, $result);
$page_title = $result_explode[1];

if ($result_explode[0] == “1”) {

$where = “($event_table.race_id = 1 OR $event_table.race_id = 2)”;

} elseif ($result_explode[0] == “2”) {

$where = “($event_table.race_id = 3)”;

} elseif ($result_explode[0] == “3”) {

$where = “($event_table.race_id = 4)”;

} elseif ($result_explode[0] == “4”) {

$where = “($event_table.race_id = 5 OR $event_table.race_id = 6 OR $event_table.race_id = 7)”;

} elseif ($result_explode[0] == “5”) {

$where = “($event_table.race_id = 8)”;

} elseif ($result_explode[0] == “6”) {

$where = “($event_table.race_id = 9 OR $event_table.race_id = 10 OR $event_table.race_id = 11)”;

} elseif ($result_explode[0] == “7”) {

$where = “($event_table.race_id = 12)”;

} elseif ($result_explode[0] == “8”) {

$where = “($event_table.race_id = 13)”;

} elseif ($result_explode[0] == “9”) {

$where = “($event_table.race_id = 14 OR $event_table.race_id = 15 OR $event_table.race_id = 16)”;

} elseif ($result_explode[0] == “10”) {

$where = “($event_table.race_id = 17 OR $event_table.race_id = 18 OR $event_table.race_id = 19 OR $event_table.race_id = 20)”;

} elseif ($result_explode[0] == “11”) {

$where = “($event_table.race_id = 21 OR $event_table.race_id = 22 OR $event_table.race_id = 23 OR $event_table.race_id = 24)”;

} elseif ($result_explode[0] == “12”) {

$where = “($event_table.race_id = 25)”;

} else { //No valid membership number, kill the script.

echo ‘

Ooops.. looks like you made a mistake! Best go back…

‘;

exit();

}

require_once(‘/websites/ma/manlyswimclub.org.au/wp-includes/mysqli_connect.php’); //Connect to the DB

// Make the query:

$q = “SELECT CONCAT($swimmer_table.firstname, ‘ ‘, $swimmer_table.lastname) AS Swimmer, $swimmer_table.category, SUM($race_table.points) as totalpoints, $swimmer_table.membership_number
FROM $race_table INNER JOIN $event_table ON $race_table.event_id = $event_table.race_id
INNER JOIN $swimmer_table ON $race_table.membership_number = $swimmer_table.membership_number
WHERE $where and $race_table.championship = ‘No’
GROUP BY membership_number
ORDER BY totalpoints DESC, $swimmer_table.lastname
LIMIT 30”;

$r = @mysqli_query ($dbc, $q); // Run the query

//Count the number of records:

$num =@mysqli_num_rows($r);

if ($num>0) { // If it ran OK, display the records.

// Table header.

echo “

$result_explode[1]

“;
echo ‘

‘;

// Fetch and print all the records
$counter = 1;
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {

echo ‘

‘;
$counter++; //increment counter by 1 on every pass
} // End of WHILE loop

echo ‘

Position Swimmer Category Points
‘ . $counter . ‘ ‘ . $row[‘Swimmer’] . ‘ ‘ . $row[‘category’] . ‘ ‘ . $row[‘totalpoints’] . ‘

‘; // Close the table.

//This is the end of all the loops and Else Ifs additional Output tables should be above this.

mysqli_free_result($r); // Free up the resources.

} else {

//Public message:

echo ‘

There are no results for this event

‘;

// Debug messgae:

// echo ‘

‘ . mysqli_error($dbc) . ‘

Query: ‘ . $q . ‘

‘;

}

mysqli_close($dbc); // Close the database connection.

} else {

//Public message:

echo ‘

You have access this page incorrectly

‘;

}

echo ‘


‘;

[/insert_php]