#!/usr/bin/env ruby
# coding: utf-8

require'cgi'
c = CGI.new(:accept_charset => "UTF-8")
require'sqlite3'

print <<EOF
Content-type: text/html; charset=utf-8

<!DOCTYPE html>
<html>
<head><title>表示するだけDB</title>
<style type="text/css">
<!--
 -->
</style>
</head>
<body>

<form method="POST" action="./ans.rb">
EOF

SQLite3::Database.new("question.db") do |db|
  db.results_as_hash = true
  
  toi = ""
  ans = ""
  puts"問題.db"
  db.execute("select * from mondai") do |f|
    #printf("%d, %s, %s\n", f["id"], f["toi"], f["ans"])
    id = f["id"]
    toi = f["toi"]
    ans = f["ans"]
    printf("<h1>問題！ No.%s\n", id)
    printf("<h2>問題: %s </h2>", toi)
    print("<h3>答えを入力してね！<input type=\"text\" name=\"anser\" size=\"15\" maxlength=\"5\"></h3>")
    print("<input type=\"submit\" value=\"ok\">")
    #printf("<h2>答えは %s だよ</h2>", ans)
  end
  puts("</form>")
  puts("</body>\n</html>")
end
