Note that there are some explanatory texts on larger screens.

plurals
  1. POSinatra Ruby iterate SQLite data into one HTML column
    primarykey
    data
    text
    <p>I've got the following SQLite table in my Sinatra app:</p> <pre><code>+----------------------------------+ | location area | +----------------------------------+ | Maine 1 | | Syracuse 2 | | Northport 3 | | NYC 4 | | Coatesville 4 | | Erie 4 | | Dayton 5 | | Chicago 6 | | Dallas 6 | +----------------------------------+ </code></pre> <p>I'd like to create an HTML table from this data that looks like the following:</p> <pre><code> &lt;table&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;Area 1&lt;/th&gt; &lt;th&gt;Area 2&lt;/th&gt; &lt;th&gt;Area 3&lt;/th&gt; &lt;th&gt;Area 4&lt;/th&gt; &lt;th&gt;Area 5&lt;/th&gt; &lt;th&gt;Area 6&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;Maine&lt;/td&gt; &lt;td&gt;Syracuse&lt;/td&gt; &lt;td&gt;NorthPort&lt;/td&gt; &lt;td&gt;NYC&lt;/td&gt; &lt;td&gt;Dayton&lt;/td&gt; &lt;td&gt;Chicago&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;Coatesville&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;Dallas&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;Erie&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; </code></pre> <p>I can easily iterate through each area and the locations contained within with two nested loops, but because of the way td and tr work in tables I'm not sure how to iterate each area's locations into a single column</p> <p>I think I've got the table head down:</p> <pre><code> &lt;thead&gt; &lt;tr&gt; &lt;% @table_areas.each do |x| %&gt; &lt;th&gt;&lt;%= x.area %&gt;&lt;/th&gt; &lt;% end %&gt; &lt;/tr&gt; &lt;/thead&gt; </code></pre> <p>but I can't seem to figure out the rest. The areas and locations within each area will be changing frequently, so I need this to be created dynamically.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload