The mgiSearchDatabase Tag

Tag Behavior

The mgiSearchDatabase tag submits a search query to a database and displays the formatted results of that query.


Tag Syntax

The mgiSearchDatabase tag has 5 required parameters and 11 optional parameters. The tag form is:

<mgiSearchDatabase databaseFileLocation="File Path" 
tableName="Name" searchFormatFileLocation="File Path" 
searchButtonValue="Button Name"
resultsFormatFileLocation="File Path" 
resultsTemplateFileLocation="File Path"
nextButtonValue="Button Name" previousButtonValue="Button Name"
displayItem="Yes/No" displayTemplateField="Database Field"
displayRecordButtonValue="Name"
postTarget="File Path" orderByField="Database Field"
reverseOrder="Yes/No" resultsLimitPopupValues="Integer List" 
setResultCount="Yes/No">

Required Parameters:

  • databaseFileLocation="File Path" where "File Path" is the relative path to the database you wish to search.
  • tableName="Name" where "Name" is the name of the table you wish to search.
  • searchFormatFileLocation="File Path" where "File Path" is the relative path to the search format file which specifies the format of the database search form. The search format file can contain form components including text fields, text areas, popup menus, radio buttons, checkboxes, and hidden fields. In addition, the search format file may include the variables listed below.
  • resultsFormatFileLocation="File Path" where "File Path" is the relative path to the results format file which specifies the overall structure of the search results.
  • resultsTemplateFileLocation="File Path" where "File Path" is the relative path to the results template file which specifies the format of each individual search result.

Optional Parameters:

  • searchButtonValue="Button Name" where "Button Name" is the name of the submit button that is displayed by the mgiSearchButton variable in the search format file. The default name is "Search".
  • nextButtonValue="Button Name" where "Button Name" is the name of the submit button that is displayed by the mgiNextButton variable in the results format file. The default name is "Next".
  • previousButtonValue="Button Name" where "Button Name" is the name of the submit button that is displayed by the mgiPreviousButton variable in the results format file. The default name is "Previous".
  • displayItem="Yes" or "No" where "Yes" allows you to display each product individually with a display template file and "No" does not allow you to display each product individually with a display template file. If the displayItem parameter is set to "Yes", then the displayTemplateField parameter is required.
  • displayTemplateField="Database Field" where "Database Field" is the database field name which contains the display template path for each item. The database field name is case-sensitive. If the displayTemplateField parameter is included, then the displayItem parameter is required.
  • displayRecordButtonValue="Button Name" where "Button Name" is the name of the submit button that is displayed by the mgiDisplayRecordButton variable in the results template file. The default name is "View Item".
  • postTarget="File Path" where "File Path" is the relative path to the file where results are displayed. The default post target is the same page containing the mgiSearchDatabase tag. If the post target is a separate file, that file must contain the same mgiSearchDatabase tag and parameters as the search page.
  • orderByField="Database Field" where "Database Field" is the database field name used to order the results (in ascending order by default - see reverseOrder). The database field name is case-sensitive. The default order of results is the order in which they were entered into the database. Any database field used to order results must be indexed when it is created in the mgiEditDatabase interface.
  • reverseOrder="Yes/No" where "Yes" indicates that ordered search results are displayed in descending order (Z to A and largest to smallest) and "No" indicates that ordered search results are displayed in ascending order (A to Z and smallest to largest). The default is "No". To use the reverseOrder parameter, you must also include the orderByField parameter.
  • resultsLimitPopupValues="Integer List" where "Integer List" is a comma delimited list of integers that will display in the popup menu called by the mgiResultsLimitPopup variable. The first value in the list will be the selected value. The default values are 5, 10, 15, 20 and 25.
  • setResultCount="Yes/No" where "Yes" indicates that a variable named mgiResultCount containing the total number of results returned during a search is set and "No" indicates that the variable is not set. The default is "No". The total number of records may be displayed anywhere on the results page after the mgiSearchDatabase tag by using an mgiGet tag with the "mgiResultCount" variable name. Caution: In order to provide this information, the internal MGI database must interate through all results before the page is served. This may delay the page serving for large numbers of results.

Search Format File Elements:

  • mgiResultsLimitPopup - The mgiResultsLimitPopup variable creates a popup menu that limits the number of results displayed to 5, 10, 15, 20 or 25. If you use the mgiResultsLimitPopup variable in the search format file, then you must use the mgiNextButton and mgiPreviousButton variables in the results format file. If the mgiResultsLimitPopup is not included in the search format file, results are limited to 25 by default. To view additional sets of 25 default results, the mgiNextButon and mgiPreviousButton variables must be included in the results format file. To override the default results limite (25) without requiring a visible pop-up menu, include a hidden field in the search format file named "mgiSearchDatabaseResultsLimit" with the results limited listed in the value parameter. For example, to limit all searches to 50 results per page, enter the following code in the search format file:
<input type="hidden" name="mgiSearchDatabaseResultsLimit" value="50">
  • mgiSearchButton - The mgiSearchButton variable creates a submit button that posts search queries to the database.
  • Image Search Button - To use an image rather than a submit button to submit searches, enter the image input type and name it "mgiSearchDatabaseAction=performSearch".
<input type="image" name="mgiSearchDatabaseAction=performSearch" 
src="search.gif">
  • Standard Searches - In the search format file, search a database field by naming a form element with the syntax "field=DatabaseFieldName". For example, to use a text field and search the "Category" database field, enter the following code in the search format file:
<input type="text" name="field=Category">
  • Relational Searches - In the search format file, perform relational searches (greater than, less than, greater than or equal to and less than or equal to) by naming a form element with the syntax "relationship=ComparisonType&field=DatabaseFieldName". Valid comparison types include "greaterThan", "lessThan", "greaterThanorEqualTo", and "lessThanorEqualTo". Relational searches only function with integer, floating point and boolean database fields. For example, to use a text field and search the "Price" database field for prices that are less than the amount entered, insert the following code in the search format file:
<input type="text" name="relationship=lessThan&field=Price">
  • Exact Match Searches - In the search format file, perform exact searches by naming a form element with the syntax "match=Exact&field=DatabaseFieldName". Currently the only type of match is "Exact". The match designation must come before the "field=DatabaseFieldName" designation. Exact match searches only function with database fields that are short text or long text types. For example, to use a text field and perform exact searches in the "Description" database field, enter the following code in the search format file:
<input type="text" name="match=Exact&field=Description">

Results Format File Variables:

  • mgiSearchResults - The mgiSearchResults variable denotes the location of individual search results that are formatted by the results template file.
  • mgiNextButton - The mgiNextButton variable creates a submit button labeled "Next" which posts additional results in the increment specified by mgiResultsLimitPopup.
  • mgiPreviousButton - The mgiPreviousButton variable creates a submit button labeled "Previous" which posts the previous set of results in the increment specified by mgiResultsLimitPopup.

Results Template File Variables:

  • mgiDisplayRecordButton - Displays a "View Item" button for each result that is linked to the display template for that result.


Example Usage and Output

<mgiSearchDatabase 
databaseFileLocation="ProductDB22"
tableName="Products"
searchFormatFileLocation="searchformat.txt"
resultsFormatFileLocation="resultsformat.txt"
resultsTemplateFileLocation="resultstemplate.txt"
displayItem="yes"
displayTemplateField="TemplateName" 
postTarget="searchresults.html"
orderByField="Price">

The format of a database search will appear with the form components included in the search format file. For example, a simple search format might only consist of a label, text field and mgiSearchButton variable such as:

Keywords:

In this example, the results are structured in a table with a header row and each search result is structured as an additional row in the table. The results format file contains the "Search Results" label and the table headers while the results template file contains the row and column information for each book. The "View Item" button is a link to the individual display template file for each item.


Suggested Usage

  • Searchable Databases
  • Database-Driven Shopping Baskets


[Return to the Referencing MGI Menu]


[User Guide Main Menu] [Understanding MGI Menu] [Using MGI Menu] [Referencing MGI Menu]