Chapter 4. HTMLGEN - Generating an html table dynamically

Type: standalone function

Location: nosod.lib

htmlgen(arg1, arg2)

Input:

Output: string (returned)

This function has for goal to generate automatically an html table content. The approach is to provide in 'arg1' the name of the array prepared by a previous process. This array must be two dimensions, where the first dimension is the row (starting at 0), and the second dimension is the column (starting at 0).

In arg2, you put as string a subpart of html table, identifying the row template. Inside the row template, put the characters '++vx++' at each place of a data, where x is the column number + 1 (means you start with ++v1++).

The function will return the complete html table generated. It's usefull when you generate a table from a database query, and that you do not know in advance how must row the table will contain. This function can be used also for generating html dropdowns and lists, as the template principle is the same.

Example: Suppose your html template file contain something like

"<TABLE>$IN0K_INFO</TABLE>"

The source code generating the html output will be something like:

	"$query=$IN0DB->queryExec("SELECT NAME,FIRSTNAME FROM PEOPLE WHERE YEAROFBIRTH=2000");$i=0; 
 while ($r = $IN0DB->queryFetch($query))  
  {
   $IN0K_INFO[$i][0]=$r["NAME"];
   $IN0K_INFO[$i][1]=$r["FIRSTNAME"];
   $i++;
  }

 eval(htmlgen("IN0K_INFO","<tr>
    <td><font face=\"Courier New\">++v1++</font></td>
    <td><font face=\"Courier New\">++v2++</font></td>
  </tr>"));
"