Hi,
jpadie wrote me this script for outputting scores from different races. (For which I'm thankfull eternally)
It does work nice, but there's one little thing I'd like enhanced. the sorting of the columns.
I've looked into the sort() function but I don't get it working the way I want.
All races have their own date, which is stored in the table "wedstrijd" field name is "Datum".
I'd like to have the races displayed chronological (is this correct written?).
This is the script:
jpadie wrote me this script for outputting scores from different races. (For which I'm thankfull eternally)
It does work nice, but there's one little thing I'd like enhanced. the sorting of the columns.
I've looked into the sort() function but I don't get it working the way I want.
All races have their own date, which is stored in the table "wedstrijd" field name is "Datum".
I'd like to have the races displayed chronological (is this correct written?).
This is the script:
Code:
<?php
include("../../Loginsys/include/session.php");
if($session->logged_in){
?>
<style type="text/css">
<!--
body {
background-image: url(../../images/bg_grad.jpg);
margin-top: 30px;
}
.style1 {
color: #FFFFFF;
font-weight: bold;
font-size: 14pt;
}
-->
</style>
<?php
require_once('../../Connections/ASN.php'); ?>
<?php
error_reporting(E_ALL);
mysql_select_db($database_ASN, $ASN);
$sql = "SELECT `wedstrijd`.`Naam` AS `wedstrijd`,`klasse`.`Klasse`,`overzicht`.`Voornaam` AS `Voornaam`,`deelnemer`.`Naam` AS `Achternaam` , `overzicht`.`Percentage` AS `Perc` FROM `overzicht` INNER JOIN `deelnemer` ON (`overzicht`.`DeelnemerId` = `deelnemer`.`Id`) INNER JOIN `wedstrijd` ON (`overzicht`.`WedstrijdId` = `wedstrijd`.`Id`) INNER JOIN `klasse` ON (`overzicht`.`KlasseId` = `klasse`.`Id`) WHERE (`klasseID` = 1) ORDER BY Voornaam";
$result = mysql_query ($sql) or die ("Query failed ".mysql_error());
// printing HTML result
//read every row into arrays
$athletes = array();
$races = array();
while ($row=mysql_fetch_assoc($result)):
//first the race
if (!in_array($row['wedstrijd'],$races)): //this builds an array of race names for later use
$races[] = $row['wedstrijd'];
endif;
$athletes[$row['Voornaam']." ".$row['Achternaam']][$row['wedstrijd']] = $row['Perc'];
endwhile;
//we now have two nicely formed arrays
//alphabetise the races
//sort($races);
//start the table plot
?>
<CAPTION>
<div align="center" class="style1">Overzicht behaalde percentages
</div>
<table border="1">
<tr>
<th><u>Wedstrijd <br>
</u><br>
Deelnemer</th>
<?
foreach ($races as $val):
?> <th><?=$val?></th> <?
endforeach;
?>
</tr>
<?
//now the header rows are down
foreach ($athletes as $key=>$val): //athletes names are stored in the key
?>
<tr><td nowrap><?=$key?></td>
<?
foreach($races as $race):
$perc = isset($val[$race]) ? $val[$race] : "--"; //is did not compete
$tmpperc = ($perc)*100;
$totperc = round($tmpperc, 3);
?><td><?=$totperc?></td><?
endforeach;
?></tr><?
endforeach;
?>
</table>
<?php
}
if(!$session->logged_in){
echo "Je bent niet ingelogd, dus geen toegang tot deze pagina.";
}
?>