#!/usr/bin/env ruby # coding: utf-8 require'sqlite3' require'cgi' c = CGI.new(:accept_charset => "UTF-8") print <<EOF Content-type: text/html; charset=utf-8 <DOCTYPE html> <head> <meta charset=utf-8> <title>ランキング</title> <link rel="stylesheet" type="text/css" href="root/editor.css"> <style> <!-- --> </style> </head> <body> EOF SQLite3::Database.new("ranking.db") do |db| db.results_as_hash = true name = "" i = 1 a = 1 o = 1 puts("<h1>問題1:ランキング</h1>") db.execute("select * from ranking") do |f| name = f["name"] printf("<p>%d:%s</p>\n",i, name) i += 1 if i == 6 break end end puts("<h1>問題2:ランキング</h1>") db.execute("select * from ranking2") do |f| name = f["name"] printf("<p>%d:%s</p>\n",a, name) a += 1 if a == 6 break end end puts("<h1>問題3:ランキング</h1>") db.execute("select * from ranking3") do |f| name = f["name"] printf("<p>%d:%s</p>\n",o, name) o += 1 if o == 6 break end end end