founditems

[founditems], the companion context to [search], loops through the records retrieved by the search, and provides the means to display data from each record.
The [founditems] context goes between the search tags. If the search specified a maximum number of matches, then only that many will be displayed in the [founditems] loop.

Example:

[search db=xx.db&eqCITYdata=Chicago]
[founditems]
[index]. <b>[Name]</b>, [Address], [City]<hr>
[/founditems]
[/search]


This will display a numbered list of people with a horizontal rule separating each.

When you are inside a search, and inside the [founditems] tags, you can retrieve all fields from the current record. These values can be easily intermixed with your html, as in the sample above. In addition, [index] is a counter that has many practical uses beyond the simple numbering seen here.

[fieldname]Enclose any fieldname in square brackets to display the value
[index] A number indicating this record's placement in the list. Note that this number is not taken from the database, but is purely a counter as the records are retrieved. When records are split into chunks with the [shownext] context, subsequent pages will start with the index true to the total search, not just the group found on that page.
[break] From version 8.1, if the [founditems] context sees the [break] tag while executing a loop, it will stop looping, once it finishes the current loop. Thus the [break] tag should only appear in a [showif] statement that is evaluated at the end (bottom) of the loop.


You also use the [founditems] within a [SQL] context, to list the records resulting from a successfull ODBC/SQL query.

The [founditems] context is also used within a [SQLresult] context, to list the records resulting from a successfull Native SQL query.
When used within [SQLresult], the new 'Iterate' parameter can be specified to control the behavior of the [founditems] context.

In setting the 'iterate' parameter to 'manual', the [founditems] context behaves more like a collection. The WebDNA programmer can retrieve the found records in any manner they wish.

ParameterDescription
Iterate

Only available within [SQLresult]

(Optional) - Manual/Auto - When set to MANUAL, the [founditems] context switches to 'manual' mode. The new [Seek] tag must then be used to 'move' the record set cursor. The cursor is always initialized to the first record position. When set to Auto - [founditems] reverts to default behavior, iterating the record set one record at a time, starting from the first item, and ending with the last item.


The following tags are available inside a [founditems] context:

TagDescription
The following tags are only valid when [founditems] is used with a [SQLresult] context.
[Field Params]The [field] tag is used within [founditems] to return information about a particular field of the current record.
Parameters:
seek (required) - The seek parameter uses a prefix-qualified naming semantic to select a specific field of the current record. You can use one of two possible prefixes for the value of the seek parameter... either named or ordinal; follow this with a ":" and the actual value which identifies the field (according to the prefix-qualifier).
For example:
seek=ordinal:1 - would select the first field
seek=named:employeeID - would select the field named "employeeID"

get (optional) - The get parameter accepts one of seven possible enumerated values:
NAME - Retrieves the field name.
ORDINAL - Retrives the field position.
DATATYPE - Retrievs the field data type.
WIDTH - Retrieves the max data length.
ALLOWNULL - T/F Resolves to 'T' if the field will accept a NULL value.
ISNULL - T/F Resolves to 'T' if the field value is NULL.
VALUE - Retrieves the field value.

raw (optional) - When retrieving field data where the field data type is: DATE, TIME, or DATETIME , WebDNA will 'interpret' the data based on the user defined WebDNA preferences for displaying Dates and Times.

However, if you wish to display the data in its 'raw' format, you can set the 'raw' parameter to 'T'.


For example:

[founditems]
[dateacquired]
[field seek=named:dateAcquired&get=value&raw=T]
[/founditems]


This would result in something like...
04/23/2010
2010-04-23

You can see that the second line displays the data value in its 'native' format (MySQL stores dates in YYYYY-MM-DD).

[Seek Params]When the 'iterate' parameter for [founditems] is set to 'manual'. The [seek] tag is used to position the result set 'cursor' to a particular record.


Parameters:
To (required) - Can be one of four values:
First - set the cursor to the first record.
Last - set the cursor to the last record.
Prev - set the cursor back one record.
Next - set the cursor ahead one record.



Example WebDNA code:
[SQLresult result_ref=rs1]
List records in reverse order:
<table>
<tr><th>ID</th><th>Date Acquired</th><th>Comments</th></tr>
[founditems iterate=manual]
[seek to=last]
[loop start=1&end=[numfound]]
<tr><td>[inventoryID]</td><td>[dateAcquired]</td><td>[comments]</td></tr>
[hideif [index]=[numfound]][seek to=prev][/hideif]
[/loop]
[/founditems]
</table>
[/SQLresult]