Search Context [Search Criteria]Found Items[/Search]
Searches a database and displays the found records.
SQL/ODBC Note: To search through an ODBC-compliant database, use the [SQL] context.

To display search results from a database, place a [Search] context into a WebDNA template. You may specify any database and any search criteria. You may put as many [Search] contexts into a template as you want, and you may 'nest' them inside of each other to create relational searches between multiple databases. Alternately you may use the Search command from a form, and specify a template containing a [FoundItems] context.

Example (normally you would put the following text into a .tpl file on your server and use a web browser to link to it):

[Search db=xx.db&eqNAMEdata=Grant]
Found [NumFound] items<br>
[Avg Price]<br> <!-- Calculate the average of the price field of all found records -->
[Sum QtyOnHand]<br> <!-- Calculate the total of the QtyOnHand field of all found records -->
[FoundItems]
<img src="[Picture].gif"><br>
[Name], [Address], [City]<br>
[/FoundItems]
[/Search]

Whenever WebDNA encounters a [Search] context, it immediately opens the database and searches through it based on the search criteria you put into the search parameters. You nearly always place a [FoundItems]...[/FoundItems] context inside the [Search] context so you can display the information from the matching records.

Notice you can substitute any [xxx] tags in the search parameters, as in [Search db=[userDB]&eqNAMEdata=[username]].
Parameter Description
db
Name of the database you wish to search
 table
New for WebDNA 5.x
In place of a db file, you can specify a named reference to a WebDNA table object.
max
A number indicating how many records should be displayed at once before showing a list of "Show Items xx-yy" hyperlinks.

The following tags are available inside a [Search] context:
Tag Description
 [NumFound]
A number indicating how many records matched the search request.
New in 4.0[Sum field=fieldName]
Calculates the numerical sum of all the found records, using the fieldName column.
New in 4.0[Avg field=fieldName]
Calculates the numerical average of all the found records, using the fieldName column.
New in 4.0[Min field=fieldName]
Calculates the numerical minimum of all the found records, using the fieldName column.
New in 4.0[Max field=fieldName]
Calculates the numerical maximum of all the found records, using the fieldName column.
Normally you place a [FoundItems] loop inside a [Search], so you can display all the matching records. You can put any database field names inside the [FoundItems] loop to display them in the HTML.
 [ReplaceFoundItems]...[/ReplaceFoundItems] Loops though all the found items and replaces text in each record with the specified new text.
Creates a list of links that let visitors see 'chunks' of search results.

User Contributed Notes
SearchContext  

charles kline  
03/18/2003 at 18:01:42
Just a helpful shortcuts when working with searches. The docs say to sort your query you use something like:
[search db=products.db&eqSKUdatarq=[sku]&NAMEsort=1&NAMEsdir=as]
to get your products to sort by the NAME field and ascending.

There is an undocumented (I couldn't find it) shortcut version of this.
[search db=products.db&eqSKUdatarq=[sku]&asNAMEsort=1]

Less typing is always good :)

- Charles

Copyright © 2008 WebDNA Software Corporation, Inc.