Showing repeating data

Mark Birbeck's picture

In a web application that uses a standard SQL database in conjunction with some kind of server-side scripting language--Ruby on Rails, PHP, ASP, etc.--adding repeating data to an item will require an extra table in the database, and some kind of 'for' loop in the code.

A typical example of what is involved is available in the Ruby on Rails tutorial:

  1. a new table is created to hold phone numbers;
  2. a Ruby on Rails model is generated to wrap this table;
  3. the script for this model is modified to indicate that a person 'has many' phone entries, and that the phone table 'belongs to' the person table;
  4. a 'for' loop is added to the view to show all phone numbers.

We'll now show how to achieve the same effect without having to update database tables, or write language-specific looping constructs.