Newer
Older
2022-KEGO / mycgi / fi.rb
@”Sato ”Sato on 30 Oct 2022 811 bytes ちょっと変えた
#!/usr/bin/ruby
# coding: utf-8
#Encoding.default_external = 'utf-8'	# UTF-8のCSVファイルを読むため
require 'cgi'
require 'sqlite3'
#c = CGI.new(:accept_charset => "UTF-8")
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.select!{|row|
printf("<br>品名 :   「%s」<br>ごみ区分 : 「%s」 <br> <br> 備考 : %s<br>-------------------------------------------------------------------------------",row["name"], row["type"], row["remark"])}
puts("
 </body>
</html>")