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 bench.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 time_2_cents($t) {
30 $rex = "/^(\d+)m(\d\d?)\.(\d{2})s$/";
31 $m = preg_match($rex,$t,$matches);
32 if ( $m == 0 ) exit(1);
33 $t_minutes = $matches[1];
34 $t_secs = $matches[2];
35 $t_cents = $matches[3];
36 return ((int) $t_cents) + ((int) $t_secs) * 100 + ((int)$t_minutes) * 6000 ;
39 function sum_time($t1, $t2) {
42 $rex = "/^(\d+)m(\d\d?)\.(\d{2})s$/";
43 $m1 = preg_match($rex,$t1,$matches1);
44 $m2 = preg_match($rex,$t2,$matches2);
45 if ($m1 != 0 && $m2 != 0) {
46 $t1_minutes = $matches1[1];
47 $t2_minutes = $matches2[1];
48 $t1_secs = $matches1[2];
49 $t2_secs = $matches2[2];
50 $t1_cents = $matches1[3];
51 $t2_cents = $matches2[3];
52 $time1 = ((int) $t1_cents) + ((int) $t1_secs) * 100 + ((int)$t1_minutes) * 6000 ;
53 $time2 = ((int) $t2_cents) + ((int) $t2_secs) * 100 + ((int)$t2_minutes) * 6000 ;
54 $sum = $time1 + $time2;
56 $sec = ($sum % 6000) / 100;
57 $cent = ($sum % 6000) % 100;
58 return sprintf("%dm%02d.%02ds",$min,$sec,$cent);
64 function group_array_by_mark($a) {
67 if ($rc[$x['mark']] == NULL) {
70 foreach ($rc[$x['mark']] as $k => $v) {
71 $rc[$x['mark']][$k] = sum_time($v, $x[$k]);
75 return array_values($rc);
78 function array_to_combo($l,$a) {
79 echo "<select name=\"$l\">";
80 echo "<option value=\"--\">--</option>";
81 foreach ($a as $k => $v) {
82 foreach( array_keys($v) as $k1 => $i) {
83 echo "<option value=\"{$v[$i]}\">{$v[$i]}</option>";