4 $db = mysql_pconnect("localhost","helm");
5 mysql_select_db("matita");
6 if (preg_match("/TIME_TO_SEC/",$q)) {
8 $q = preg_replace("/group by mark/","",$q);
9 $q = preg_replace("/SEC_TO_TIME\(SUM\(TIME_TO_SEC\(([^)]+)\)\)\)/","$1",$q);
11 $rc = mysql_query($q,$db);
13 die("Query failed: " . mysql_error());
16 while( $row = mysql_fetch_array($rc, MYSQL_ASSOC)){
19 mysql_free_result($rc);
22 return group_array_by_mark($result);
28 function sum_time($t1, $t2) {
31 $rex = "/^(\d+)m(\d{2})\.(\d{2})s$/";
32 $m1 = preg_match($rex,$t1,$matches1);
33 $m2 = preg_match($rex,$t2,$matches2);
34 if ($m1 != 0 && $m2 != 0) {
35 $t1_minutes = $matches1[1];
36 $t2_minutes = $matches2[1];
37 $t1_secs = $matches1[2];
38 $t2_secs = $matches2[2];
39 $t1_cents = $matches1[3];
40 $t2_cents = $matches2[3];
41 $time1 = ((int) $t1_cents) + ((int) $t1_secs) * 100 + ((int)$t1_minutes) * 6000 ;
42 $time2 = ((int) $t2_cents) + ((int) $t2_secs) * 100 + ((int)$t2_minutes) * 6000 ;
43 $sum = $time1 + $time2;
45 $sec = ($sum % 6000) / 100;
46 $cent = ($sum % 6000) % 100;
47 return sprintf("%dm%02d.%02ds",$min,$sec,$cent);
53 function group_array_by_mark($a) {
56 if ($rc[$x['mark']] == NULL) {
59 foreach ($rc[$x['mark']] as $k => $v) {
60 $rc[$x['mark']][$k] = sum_time($v, $x[$k]);
64 return array_values($rc);
67 function array_to_combo($l,$a) {
68 echo "<select name=\"$l\">";
69 echo "<option value=\"--\">--</option>";
70 foreach ($a as $k => $v) {
71 foreach( array_keys($v) as $k1 => $i) {
72 echo "<option value=\"{$v[$i]}\">{$v[$i]}</option>";