Contest
$DEBUG = false;
if ($DEBUG):
require(‘/home/gooldorg/public_html/bridge_blogging/contest/contest-settings.php’);
$dbName = ‘gooldorg_bridgeblogging’;
$dbUser = ‘gooldorg_bbuser’;
$dbPswd = ‘K1ngLe2r2’;
$dbHost = ‘localhost’;
else:
require(‘/home/content/53/6837553/html/www/bridgeblogging/contest/contest-settings.php’);
$dbName = ‘blo1107710202276’;
$dbUser = ‘blo1107710202276’;
$dbPswd = ‘K1ngLe2r2’;
$dbHost = ‘blo1107710202276.db.6837553.hostedresource.com’;
endif;
function dbError($msg) {
$_SESSION[‘dberror’] = ‘An error occured while doing the report query. The system reported:
‘ . $msg;
header(‘Location: http://bridgeblogging.com/contest/dberror.php’);
exit;
}
date_default_timezone_set(‘GMT’);
/* Before wasting CPU cycles on anything else, make sure we can get at the database! */
@ $db = new mysqli($dbHost, $dbUser, $dbPswd, $dbName);
if (mysqli_connect_errno()) {
$_SESSION[‘dberror’] = ‘Could not connect to database: ‘ . mysqli_connect_error();
header(‘Location: http://bridgeblogging.com/contest/dberror.php’);
exit;
}
$theQuery = ‘
SELECT
“0” AS “Total Pts”,
name AS “Real Name”,
pseudonym AS “Pseudonym”,
email AS “E-mail Address”,
quarter_0 AS “Quarter Final (1)”,
quarter_1 AS “Quarter Final (2)”,
quarter_2 AS “Quarter Final (3)”,
quarter_3 AS “Quarter Final (4)”,
quarter_4 AS “Quarter Final (5)”,
quarter_5 AS “Quarter Final (6)”,
quarter_6 AS “Quarter Final (7)”,
quarter_7 AS “Quarter Final (8)”,
“0” AS “QF Pts”,
semi_0 AS “Semifinal (1)”,
semi_1 AS “Semifinal (2)”,
semi_2 AS “Semifinal (3)”,
semi_3 AS “Semifinal (4)”,
“0” AS “SF Pts”,
final_0 AS “Finalist (1)”,
final_1 AS “Finalist (2)”,
“0” AS “F Pts”,
bronze AS “Bronze Medalist”,
“0” AS “B Pts”,
gold AS “Gold Medalist”,
“0” AS “G Pts”,
senior AS “Senior Teams Winner”,
date_added AS “Date Submitted”
FROM
bbc_contest
ORDER BY date_added
‘;
$theQueryResult = array();
$reportResult = array();
$tempResult = array();
$ptrArray = array();
if (!($queryHandle = $db->query($theQuery, MYSQLI_USE_RESULT))) {
dbError($db->error);
}
/* Process (store) the retrieved data */
while ($theRow = $queryHandle->fetch_object()) {
$theQueryResult[] = $theRow;
}
$queryHandle->close();
$rowsRetrieved = count($theQueryResult);
foreach ($theQueryResult as $theRow):
foreach ($theRow as $theCol => $theValue): // cannot modify loop variable
$tempRow[$theCol] = $theValue; // $tempRow[] is what will be displayed
endforeach;
/* Compute scores for this entry */
for ($i = 0; $i < 8; $i++): // Quarter Finals
$thePick = $tempRow[‘Quarter Final (‘ . ($i + 1) . ‘)’];
foreach ($quarterfinal as $aRealWinner):
if ($thePick == $aRealWinner):
$tempRow[‘QF Pts’] += QUARTER;
break;
endif;
endforeach;
endfor;
for ($i = 0; $i < 4; $i++): // Semifinals
$thePick = $tempRow[‘Semifinal (‘ . ($i + 1) . ‘)’];
foreach ($semifinal as $aRealWinner):
if ($thePick == $aRealWinner):
$tempRow[‘SF Pts’] += SEMI;
break;
endif;
endforeach;
endfor;
for ($i = 0; $i < 2; $i++): // Finals
$thePick = $tempRow[‘Finalist (‘ . ($i + 1) . ‘)’];
foreach ($final as $aRealWinner):
if ($thePick == $aRealWinner):
$tempRow[‘F Pts’] += AFINAL;
break;
endif;
endforeach;
endfor;
if ($tempRow[‘Bronze Medalist’] == $bronze):
$tempRow[‘B Pts’] += BRONZE;
endif;
if ($tempRow[‘Gold Medalist’] == $gold):
$tempRow[‘G Pts’] += GOLD;
endif;
$tempRow[‘Total Pts’] =
$tempRow[‘QF Pts’] +
$tempRow[‘SF Pts’] +
$tempRow[‘F Pts’] +
$tempRow[‘B Pts’] +
$tempRow[‘G Pts’];
$tempResult[] = $tempRow; // build report, one row at a time
endforeach;
/* Sort the results by Total Pts */
foreach ($tempResult as $key => $theRow):
$ptrArray[$key] = $theRow[‘Total Pts’];
endforeach;
arsort($ptrArray);
foreach ($ptrArray as $key => $theRow):
$reportResult[] = $tempResult[$key];
endforeach;
/* __________________________________________________________________________ */
?>
BridgeBlogging Pick the Winners Contest — Standings as of echo strftime(‘%Y-%m-%d %H:%M’); ?>
14th World Bridge Games at the World Mind Games in Lille, France — Open Series
foreach ($reportResult as $theRow):
$entrant = $theRow[‘Pseudonym’];
if (empty($entrant)):
$entrant = $theRow[‘Real Name’];
endif;
$detailRow = ”; $detailRow .= ”;
for ($team = 0; $team < 8; $team++):
$detailRow .= ”;
endfor;
$detailRow .= ‘
‘;
for ($team = 0; $team < 4; $team++):
$detailRow .= ”;
endfor;
$detailRow .= ‘
‘;
for ($team = 0; $team < 2; $team++):
$detailRow .= ”;
endfor;
$detailRow .= ‘
‘;
echo $detailRow;
endforeach;
?>
Pts | Name | Event | Picks | |||||||
---|---|---|---|---|---|---|---|---|---|---|
‘ . $theRow[‘Total Pts’] . ‘ | ‘ . $entrant . ‘ | Quarter Finalists: | ‘ . $theRow[‘Quarter Final (‘ . ($team + 1) . ‘)’] . ‘ | |||||||
Semifinalists: | ‘ . $theRow[‘Semifinal (‘ . ($team + 1) . ‘)’] . ‘ | |||||||||
Finalists: | ‘ . $theRow[‘Finalist (‘ . ($team + 1) . ‘)’] . ‘ | |||||||||
Bronze Medalist: | ‘ . $theRow[‘Bronze Medalist’] . ‘ | |||||||||
Gold Medalist: | ‘ . $theRow[‘Gold Medalist’] . ‘ | |||||||||
Senior Teams Winner: | ‘ . $theRow[‘Senior Teams Winner’] . ‘ |