Web Programming Languages

Ruby Source Code: dbread.rb

#!/usr/bin/ruby
require 'cgi'
#require 'mysql'
#require './connect'
require './common'

#----------------------------------------------------------
#   The Web Language Project
#   Mark Brautigam
#   May-June 2015
#   http://www.mixed-up.com/markb/
#----------------------------------------------------------

cgi = CGI.new
puts cgi.header
headers1()
headers2()
print sidebarX("ruby", "dbread", "rb")

print %q(
  <div id="content">
    <h2>Ruby: Display MySQL Database Contents</h2>
    <table class='results db'>
      <tr><th>Park</th><th>City</th><th>State</th><th>Geo</th><th>Edit</th></tr>
)

print "<p class='error'>Ruby database functions are not installed on this server.</p>\n"

#----------------------------------------------------
#  The main Ruby code is here.
#----------------------------------------------------
#con = my_connect()
#rs = con.query('SELECT * FROM parks')
#rs.each_hash do |row|
#  print "<tr>"
#  print "<td>" + row['site'] + "</td>"
#  print "<td>" + row['city'] + "</td>"
#  print "<td>" + row['state'] + "</td>"
#  shortlat = sprintf("%.2f", row['latitude'])
#  shortlon = sprintf("%.2f", row['longitude'])
#  href = "https://www.google.com/maps/preview/@" + row['latitude'] + "," + 
#    row['longitude'] + ",12z"
#  alink = "<a target='_blank' href='" + href + "'>" + shortlat + ", " + 
#    shortlon + "</a>"
#  print "<td>" + alink + "</td>"
#  printf( "<td><a href='dbedit.rb?" + 
#        "id=%s'><img src='../images/pencilc.svg' /></a>", row['ID'])
#  print "</tr>"
#end
#----------------------------------------------------

print %q(
    </table>
    <p><a href='dbwrite.rb'>Write to this database table »</a></p>
    <p><a href='source.rb?f=7'>Show Ruby source code »</a>
  </div>
)

footers()