#!/usr/bin/env ruby # coding: utf-8 require'cgi' c = CGI.new(:accept_charset => "UTF-8") require'sqlite3' print"Content-type: text/html; charset=utf-8\n\n" anss = c["anser"] print <<EOF <!DOCTYPE html> <html> <head><title>表示するだけDB 答え</title> <style type="text/css"> <!-- --> </style> </head> <body> EOF SQLite3::Database.new("question.db") do |db| db.results_as_hash = true ans = "" db.execute("select * from mondai") do |f| ans = f["ans"] if anss == ans printf("<h1>%s</h1>\n", ans) puts("<h2>正解だよ!おめでとう!</h2>") else puts("<h2>ザンネン!今回はハズレ!</h2>") end end puts("</body>\n</html>") end