Using the HTML Table Element as a Recordset
(Page 1 of 5 )
When you query a database, the result you receive is a recordset. The form in which your result can be presented is affected by the capabilities of the language you use. This can present a challenge for certain languages. This article presents one way to meet that challenge if you program for the web.
Introduction
This article is written for those who have basic knowledge in database programming, HTML, CSS and JavaScript.
Recordset is a name given to the result of a database query. There are other names for it, such as resultSet. This result is in the memory of the client’s computer. For a language like C++, there are APIs, which link the database program (code to manipulate the data) to the database engine. These APIs have (produce) the recordset, which is accessed by the programming language (C++).
If we are to use JavaScript as the programming language, what recordset shall we use? JavaScript offers a two-dimensional array whose columns can be of different data types. The problem here is that JavaScript’s two-dimensional array is not well developed. It does not have the properties and methods that classical recordsets have.
But what about the HTML TABLE element? The HTML TABLE element has the properties and methods that classical recordsets have. The cell data is the content of a table cell. But the HTML table and its content, by default, appears on the browser page, while the content of a classical recordset does not appear on the client’s document window! If you give the HTML Table the style property, display:none, it will not appear or occupy space on the browser’s window.
Seen as a recordset, the field data of a row of the TABLE element is the content of the TD element. This can be anything; it can be text, image, video or even sound. Other recordsets do not easily take (accept) non-text objects. Clearly, the HTML TABLE element can be used as a recordset.
The HTML TABLE element as a recordset has the following advantages over classical recordsets:
It does not have to be only two-dimensional; it can be three- or even four-dimensional. When it comes to dimensions, you can make it as complex as you want. However, I will not address the two-dimensional case.
In conjunction with HTML, you need very little code (JavaScript) to make its field value (video) appear on the browser window. With another type of recordset, in conjunction with the Windows API, you need a lot of code (C++) to make the field value appear in the client’s document’s window. Note: studios use the Windows API without you being conscious of it.
If you want, you can see the content of the recordset without using code. To achieve this, simply allow the HTML TABLE (recordset) to have its default style of display:block and put it in a DIV element which has scroll bars and fixed dimensions. As you can see, you do not need JavaScript, C++, or Visual Basic.net to arrive at this situation. There is no other type of recordset whose data values you can see in the documents window, just like that.
You can give the HTML TABLE recordset field values (e.g. images) or dynamic behavior using JavaScript.
For those of you who are not used to handling recordsets by hand, know that any good container can be used as a resultset. The C++ vector container, for example, can be used as a recordset in the C++ world. The HTML TABLE element is a container. It might not look like one, but it is.
If you are dealing with the Internet and you have a basic (or small) database program to write, you have a couple of choices.
You can use HTML in place of a studio, for flexibility, and in place of the Windows API for ease of work.
You can use JavaScript instead of C++ or Visual Basic or Perl, etc., for ease of work and because it is easily available; its interpreter comes with the browser you can use the HTML TABLE element with the style property set to display:none, for single-row forms (see below), or with the default style display:block for tabular forms (see below). HTML TABLE is easily available (in browsers).
This is an aspect of web development. I will handle the case of large databases in a different series.
Next: Minimum Requirements of a Read/Write Recordset >>
More HTML Articles
More By Chrysanthus Forcha