#!/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"> <!-- tr.head {background: cyan;} th {width: 8em;} --> </style> </head> <body> 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"]) toi = f["toi"] ans = f["ans"] end #p toi printf("<h1>問題は %s だよ</h1>", toi) puts("</body>\n</html>") end