$value) {
echo "
" . $name . " " . $value;
}
**/
// connect to the hanoi database
$servername = "localhost";
$username = "gtstudent";
$password = "";
$dbname = "hanoi";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Only accept POSTed data
$data1=$_POST['textdata'];
$data2=$_POST['ttime'];
$data3 = $_POST['observer'];
if (strcmp($data2, "3487")!=0) {
// 3487 is the default time. This will only happen if no time
// was recorded in the stopwatch. So, if we do not have 3487,
// then it is a real time. So save it.
$sql = "INSERT INTO timedata (actor, witness, time) VALUES ('$data1', '$data3', '$data2');";
echo "$sql
";
$conn->query($sql);
}
?>
Hanoi Speed Results
query($sql);
// read all the results, just to determine the bounds of the graph
while (null != ($row = $result->fetch_assoc())) {
$count++;
$secs = 0;
$secs = toSecs($row["time"]);
$total = $total + $secs;
if ($mnn > $secs && $secs>0)
{
$mnn=$secs;
}
if ($max < $secs)
{
$max=$secs;
}
}
if ($count<1) {
// no data so quit
return;
}
$avg = $total / ($count-1);
$count-=1;
$csiz = 500;
$in = 70;
// start a canvas object
// rather than writing to it directly, write to it in javascript.
// So here we are using PHP to generate javascript!
?>
";
";
echo "var canvas = document.getElementById('eTTUV');\nvar ctx = canvas.getContext('2d');\nctx.strokeStyle='black';\nctx.lineWidth=0.25;";
echo "canvas.height=$csiz;";
echo "canvas.width=$csiz;";
$xsiz = $csiz-$in;
$ysiz = $xsiz;
$range = $max-$mnn;
$yyy = $ysiz-((($avg-$mnn)/$range)*$ysiz);
writeWrite($in-5, $csiz-$in, sprintf("%.2f", $mnn), 16);
writeWrite($in-5, 10, sprintf("%.2f", $max), 16);
writeWrite($in-5, $yyy, sprintf("%.2f", $avg), 16);
fillSpace($in, 0, $csiz, $csiz-$in);
writeLine($in, $yyy, $csiz, $yyy, "#FFFFFF", 1);
$ccount = -1;
$prev=$mnn;
$sql = "select * from timedata";
$result = $conn->query($sql);
while (null != ($row = $result->fetch_assoc())) {
$secs = toSecs($row["time"]);
if ($secs>0) {
if ($ccount>-1) {
$strtx = $in+(($ccount*$xsiz)/$count);
$strty = $ysiz-((($prev-$mnn)/$range)*$ysiz);
$endx = $in+(($ccount+1)*$xsiz/$count);
$endy = $ysiz-(($secs-$mnn)/$range)*$ysiz;
writeLine($strtx, $strty, $endx, $endy, "#FF00FF", 5);
}
$prev = $secs;
$ccount++;
}
}
echo "
";
?>