Dynamic Data

Examples

Dynamic Data from Databases

The table below shows a simple LIVE v-creator example in action.

The example was created using an automatically generated database module. The figure below shows the steps to creating the module.

 

  1. A simple database table called books with the columns book_id, book_title, author and ISBN was created
  2. The supplied genDBmodule utility was then run against the database table to create a database module called books.php
  3. A few simple changes were then made to the generated code to order by book title and flag rows as odd or even
  4. The books.php file is copied to the user modules directory

In total less than 5 minutes work.

To generate the above table the following HTML & v-creator tags were used:

<table>
  <tr>
    <th>Title<th>
    <th>Author<th>
    <th>ISBN<th>
  <tr>
  |{LOOP:books}|
  <tr |{COND:odd_row}|style="background: #dfdfdf;"|{CEND}|>
    <td>|{DATA:book_title}|<td>
    <td>|{DATA:author}|<td>
    <td>|{DATA:isbn}|<td>
  <tr>
  |{LEND}|
<table>

Module Reuse

We can now reuse the book module to produce other dynamic elements.

A drop down list of books:

<select>
  |{book_id=VC_NULL}|
  |{LOOP:books}|
    <option value="|{DATA:book_id}|">|{DATA:book_title}|<option>
  |{LEND}|
<select>

Or lists of data:

  • Cascading Style Sheets: The Definitive Guide, 2nd Edition
  • Essential CVS
  • HTML & XHTML: The Definitive Guide, 5th Edition
  • Learning PHP 5
  • Learning the vi Editor, 6th Edition
  • Programming PHP
  • Understanding the Linux Kernel, 2nd Edition
<ul>
  |{book_id=VC_NULL}|
  |{LOOP:books}|
    <li>|{DATA:book_author}|</li>
  |{LEND}|
</ul>

Conditional Content

v-creator also makes it easy to have content displayed based on conditional tests. As the books module has an odd/even flag it will be used to demonstrate conditional testing by only showing books from even database rows:

  • Cascading Style Sheets: The Definitive Guide, 2nd Edition
  • HTML & XHTML: The Definitive Guide, 5th Edition
  • Learning the vi Editor, 6th Edition
  • Understanding the Linux Kernel, 2nd Edition
<ul>
  |{book_id=VC_NULL}|
  |{LOOP:books}|
    |{COND:odd_row}|
      <li>|{DATA:book_author}|</li>
    |{CEND}|
  |{LEND}|
</ul>