[table name=...&fields=,,...,]<fieldname 1>,<fieldname 2>,…,<fieldname n>[/table]


Enables the WebDNA programmer to quickly create a temporary 'in line' database table that is local to the template and not part of the global database cache. A table can be used in any context that accepts a database 'db' as a parameter.


Optional Tag Parameters:

· name
- A user assigned name used to reference the table during the duration of the template.
· fields - A comma delimited, ordered, list of fieldnames to be used for the table.

Search a Table

Lets create a table and perform a basic search on it.

We use the following code...

[table name=products&fields=SKU,NAME,DESC]
1001 Red Widget A small red widget
1002 Blue Widget A small blue widget
1003 Green Widget A small green widget
[/table]

[search table=products&neSKUdata=[blank]]
Found [numfound] items in the products table.

[founditems]
[SKU] - [DESC]

[/founditems]
[/search]

Results....


Found 3 items in the products table.
1001 - A small red widget
1002 - A small blue widget
1003 - A small green widget

A table can be very useful if you want to perform a secondary search on the results of a previous search.

Examples with ConvertChars/Words

You can use a table to quick create a table to be use with the ConvertChars, and ConvertWords contexts


[table name=t1&fields=from,to]
a A
b B
c C
[/table]

[table name=t2&fields=from,to]
webdna WebDNA
tables Tables
smsi SMSI
[/table]

[convertchars table=t1]abc[/convertchars]


[convertwords table=t2]webdna tables, brought to you by smsi![/convertwords]

Results...


ABC
WebDNA Tables, brought to you by SMSI!

Example with ListFiles

Tables are also very useful for sorting/searching the results of other 'iterative' WebDNA contexts. For example, lets sort the results of a [listfiles] context...


[table name=filesort&fields=filename,size,date][!]
[/!][listfiles path=.]
[filename] [size] [createdate]
[/listfiles][/table]

Directory listing - sorted by filename

[search table=filesort&neFILENAMEdata=[blank]&asFILENAMEsort=1]
[founditems]
[filename] - [size] - [date]

[/founditems]
[/search]

Directory listing - sorted by file size

[search table=filesort&neFILENAMEdata=[blank]&asSIZEsort=1&SIZEtype=num]
[founditems]
[filename] - [size] - [date]

[/founditems]
[/search]

 

Results...

 

Directory listing - sorted by filename
Table_Context_-_---1---.tpl - 1093 - 01/02/2003
Table_Context_-_---2---.tpl - 1066 - 01/02/2003
Table_Context_-_---3---.tpl - 940 - 01/02/2003
Table_Context_-_---4---.tpl - 3445 - 01/02/2003
Table_Context_-_---5---.tpl - 529 - 01/02/2003
Table_Context_-_---6---.tpl - 166 - 01/02/2003
table_tutorial5a.inc - 2255 - 01/02/2003
Directory listing - sorted by file size
Table_Context_-_---6---.tpl - 166 - 01/02/2003
Table_Context_-_---5---.tpl - 529 - 01/02/2003
Table_Context_-_---3---.tpl - 940 - 01/02/2003
Table_Context_-_---2---.tpl - 1066 - 01/02/2003
Table_Context_-_---1---.tpl - 1093 - 01/02/2003
table_tutorial5a.inc - 2255 - 01/02/2003
Table_Context_-_---4---.tpl - 3445 - 01/02/2003

Note that we had to comment out some line endings. This is because the WebDNA that is parsed between the [table] tags must evaluate to a list of 'records', with the 'fields' delimited by tabs and each 'record' ending with a line ending (<cr><lf> or <lf> or <cr>). In other words, exactly the same format as a WebDNA database.

Lets combine this with a webdna [function] context to list all files in a folder, and its sub-folders.

The new WebDNA [function] context is described in the 'Function Context' tutorial.

Here is the code...


[function name=get_files]
[listfiles path=[in_path]]
   [!]IF this is a folder, recurse into the folder[/!]
[showif [IsFolder]=T]
[return][depth]	<b>[filename]</b>	T
[get_files root=F&in_path=[hideif [root]=TT][in_path]/[/hideif][filename]&depth=[math][depth]+1[/math]][/return]
[/showif]

[hideif [IsFolder]=T]
[return][depth]	[filename]	F
[/return][/hideif]
[/listfiles][/function]

[table name=file_tree_table&fields=depth,name,isfolder]
[get_files root=T&in_path=../../../user_files&depth=0]
[/table]

Display the folder tree of the 'user_files' folder.<br>
[search table=file_tree_table&eqISFOLDERdata=T&rank=off]
[founditems]
[loop start=0&end=[depth]]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[/loop][name]<br>
[/founditems]
[/search]
<p>
Display the complete file tree of the 'user_files' folder<br>
[search table=file_tree_table&neNAMEdata=B&rank=off]
[founditems]
[loop start=0&end=[depth]]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[/loop][name]<br>
[/founditems]
[/search]
        

Results...


Display the folder tree of the 'user_files' folder.
tutorials
Array_Context
Function_Context
ISP_Sandbox
Scope
Special_Scripts
Table_Context
XML_Contexts
XSL-XSLT_Contexts

Display the complete file tree of the 'user_files' folder

database1.db
example1.tpl
sandbox_admin_redirect.tpl
tutorials
Array_Context
Array_Context_-_---1---.tpl
Array_Context_-_---2---.tpl
Array_Context_-_---3---.tpl
Array_Context_-_---4---.tpl
Array_Context_-_---5---.tpl
Array_Context_-_---6---.tpl
Array_Context_-_---7---.tpl
array_tutorial6a.inc
create_tutorial.tpl
Function_Context
functions.db
functions_test.db
Function_Context_-_---1---.tpl
Function_Context_-_---2---.tpl
Function_Context_-_---3---.tpl
Function_Context_-_---4---.tpl
Function_Context_-_---5---.tpl
Function_Context_-_---6---.tpl
Function_Context_-_---7---.tpl
Function_Context_-_---8---.tpl
Function_Context_-_---9---.tpl
function_tutorial8a.inc
header.inc
ISP_Sandbox
ISP_Sandbox_-_---1---.tpl
ISP_Sandbox_-_---2---.tpl
ISP_Sandbox_-_---3---.tpl
ISP_Sandbox_-_---4---.tpl
ISP_Sandbox_-_---5---.tpl
ISP_Sandbox_-_---6---.tpl
Scope
products.db
Scope_-_---1---.tpl
Scope_-_---2---.tpl
Scope_-_---3---.tpl
Scope_-_---4---.tpl
Scope_-_---5---.tpl
Scope_-_---6---.tpl
Scope_-_---7---.tpl
Scope_-_---8---.tpl
Scope_-_---9---.tpl
Scope_tutorial7a.inc
testcart
Special_Scripts
Special_Scripts_-_---1---.tpl
Special_Scripts_-_---2---.tpl
Special_Scripts_-_---3---.tpl
Special_Scripts_-_---4---.tpl
Table_Context
Table_Context_-_---1---.tpl
Table_Context_-_---2---.tpl
Table_Context_-_---3---.tpl
Table_Context_-_---4---.tpl
Table_Context_-_---5---.tpl
Table_Context_-_---6---.tpl
table_tutorial5a.inc
XML_Contexts
example1.xml
XML_Contexts_-_---1---.tpl
XML_Contexts_-_---10---.tpl
XML_Contexts_-_---11---.tpl
XML_Contexts_-_---12---.tpl
XML_Contexts_-_---13---.tpl
XML_Contexts_-_---14---.tpl
XML_Contexts_-_---15---.tpl
XML_Contexts_-_---2---.tpl
XML_Contexts_-_---3---.tpl
XML_Contexts_-_---4---.tpl
XML_Contexts_-_---5---.tpl
XML_Contexts_-_---6---.tpl
XML_Contexts_-_---7---.tpl
XML_Contexts_-_---8---.tpl
XML_Contexts_-_---9---.tpl
xml_tutorial12a.inc
xml_tutorial8a.inc
XSL-XSLT_Contexts
example1.xml
example1.xsl
example2.xsl
music.db
XSL-XSLTtutorial1.inc
XSL-XSLT_Contexts_-_---1---.tpl
XSL-XSLT_Contexts_-_---2---.tpl
XSL-XSLT_Contexts_-_---3---.tpl
XSL-XSLT_Contexts_-_---4---.tpl
XSL-XSLT_Contexts_-_---5---.tpl
XSL-XSLT_Contexts_-_---6---.tpl
XSL-XSLT_Contexts_-_---7---.tpl
XSL-XSLT_Contexts_-_---8---.tpl
XSL-XSLT_Contexts_-_---9---.tpl
welcome.tpl



In the example above, we used a single table to store all the folder and file info. We could have created a separate table for each folder, which would provide more flexibility for sorting the folders and files (which is what we did to create the 'file tree' popup window used in the WebDNA Lab application.).