|
Building tables dynamically with CGI class: msg#01150lang.ruby.general
I figured out how to build tables dynamically using methods in the CGI class, but I can't figure out a way to add a header other than the method I use below. In the code below, I simply put the header row into the array of rows generated by successive fetches from the database. The problem with the method I use below is that it forces me to use <td> tags for the header columns when I would like to use <th> tags. Any suggestions? #!/usr/bin/env ruby require 'dbi' require 'cgi' # connect to the database dbh = DBI.connect('DBI:Mysql:test','','') cgi = CGI.new("html4") sth = dbh.prepare('select id, fname, lname from contact') sth.execute rows = [["ID","First","Last"]] while row = sth.fetch_array() do rows.push(row) end cgi.out { cgi.head { cgi.title{"Name"} } + cgi.body { cgi.table('border'=>'1') { rows.collect { |row| cgi.tr { row.collect { |item| cgi.td { item } } } } } } }
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: FXRuby usage: Capturing results from an FXDialogBox, Lyle Johnson |
|---|---|
| Next by Date: | Re: Handling forms on database driven websites, MikkelFJ |
| Previous by Thread: | Perl calling C calling Ruby (linking problem), Peter Munro |
| Next by Thread: | Re: Building tables dynamically with CGI class, T.M. Sommers |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |