Newer
Older
2022-KEGO / mycgi / gomi.rb
@”Sato ”Sato on 26 Oct 2022 766 bytes selectからeachに修正
#!/usr/bin/env ruby
# coding: utf-8
Encoding.default_external = 'utf-8'	# UTF-8のCSVファイルを読むため
require 'cgi'
require 'sqlite3'
c = CGI.new(:accept_charset => "UTF-8")

trash = c["gomi"]
#データベース読み取り処理は全く同じ
db = SQLite3::Database.new("gomi.db")
db.results_as_hash = true
result = db.execute("SELECT * FROM gomi where name LIKE '%#{trash}%';")

print("Content-type: text/html; charset=utf-8

<!DOCTYPE html>
<html>
<head><title>検索結果</title>
</head>
<body>
")
result.each{|row|
printf("<br>品名 :  「%s」<br>ごみ区分 : 「%s」 <br> <br> 備考 : %s<br>-------------------------------------------------------------------------------",row["name"], row["type"], row["remark"])}
puts("
 </body>
</html>")