#!/usr/bin/ruby # -*- coding: utf-8 -*- require 'cgi' require 'csv' cgi = CGI.new # フォームからのデータを取得 nickname = cgi['nickname'] selected_date = cgi['calendar'] print "<html>\n" print "<head>\n" print "<title>診断結果</title>\n" data = CSV.read("birth_stone.csv", headers:true) if row['誕生月'] == selected_date data.each{|row| printf("%sの宝石は...\n", row["誕生月"]) printf("%sだよ!\n", row["定番宝石"]) printf("宝石言葉は %s \n", row["宝石言葉"]) printf("New => %s \n おまけ1 => %s \n おまけ2 => %s \n", row["宝石言葉"],row["おまけ1"],row["おまけ2"] )} end print "</body>\n" print "</html>\n" #csv、gptさんによると・・・ CSV.foreach('date_results.csv', headers: true) do |row| if row['誕生月'] == selected_date result = row['結果'] break end end # 結果を出力 puts "Content-type: text/html; charset=UTF-8\n\n" puts "<html>" puts "<head><title>日付ごとの結果</title></head>" puts "<body>" puts "<h1>選択された日付の結果</h1>" puts "<p>#{selected_date}の結果</p>" puts "<p>#{result}</p>" puts "</body>" puts "</html>" #JAVAで年月日をわける!? <!-- 他のコンテンツ... --> <script> function toggleImage(image) { // 画像を表示/非表示に切り替える処理 } // 要素がロードされたときに実行する処理 window.onload = function() { // 要素がロードされた後で日付が変更されたときに実行する処理 document.querySelector('input[type="date"]').addEventListener('change', function() { var selectedDate = new Date(this.value); var year = selectedDate.getFullYear(); // 年 var month = selectedDate.getMonth() + 1; // 月は0から始まるため、+1して実際の月にする var day = selectedDate.getDate(); // 日 // 分割された年、月、日の表示 console.log('年: ' + year); console.log('月: ' + month); console.log('日: ' + day); }); }; </script>