How to create a two dimensional table

Dear all

I have the following data in a table and I want to create a 2-dimensional table to display it.

Table: services col01 col02 col03 AH AS 1 AH CS 2 AH MS 3 BH BS 1 BH CS 1 BH MS 1 CH IS 1 CH BS 2 CH MS 1 DH CS 1 DH MS 1

I want to have this present on web

     AS BS CS IS MS AH 1 2 3 BH 1 1 1 CH 2 1 1 DH 1 1

I only have the idea to display the column and row title. Can anyone give me some idea how to generate this dynamically?. Thanks

controllers/dashboard_controller.rb   def main     @hospital_code = Service.find_by_sql("select distinct hospital_code from services")     @service_code = Service.find_by_sql("select distinct service_code from services")   end

views/dashboard/main.html.erb <table border="1"> <tr>   <th></th> <% for s in @service_code %>   <th><%=s.col02 %></th> <% end %> </tr>

<% for h in @hospital_code %>   <tr>   <td><%=h.col01 %></td>   </tr> <% end %> </table>

Many thanks Valentino

I would suggest building a two dimensional array @values in the controller, iterating through the records and filling in the cells. This can then be displayed as rows and columns in the view. I suspect there may be more elegant ways to do this in Ruby however. Colin

I would suggest building a two dimensional array @values in the controller, iterating through the records and filling in the cells. This can then be displayed as rows and columns in the view. I suspect there may be more elegant ways to do this in Ruby however. Colin

You can create a sql query that returns the data formatted the way you want :

MODEL

If the content of Col1 and Col2 is dynamic?

I have this

MODEL

Did you realise that you have replied to a thread from 2009? I hope the OP has not been waiting all this time for an answer.

Colin