Dynamic Database Searching (i.e., MGI On-Da-Fly)
Example
- Displaying a database-driven Little League Baseball Schedule.
MGI Tags
Steps
- Create a page to display dynamic search results.
- Save the dynamic search page.
- Open the dynamic search page in a text editor.
- Insert the perform search variable, database search criteria, results
limit variables, and mgiSearchDatabase tag.
- Save the dynamic search page.
- Create a search format file in a text editor.
- Save the search format file.
- Create a results format file in a text editor.
- Save the results format file.
- Create a results template file in a text editor.
- Save the results template file.
- FTP the dynamic search page, format files and template file to the
web server running MGI.
- View the dynamic search page in a browser.
Step 1: Create a page to display dynamic search results.
- In a dynamic search, a database search is performed and results are
displayed automatically when the dynamic search page is accessed. In a
dynamic search, a search submission from a search page is not required.
Create a new page to perform the dynamic search and display the search
results.
Step 2: Save the dynamic search page.
- Save the dynamic search page and name it "dynamicsearch.html".
Step 3: Open the dynamic search page in a text editor.
- Open the dynamic search page (dynamicsearch.html) in a text editing
program that allows you to view and modify the HTML.
Step 4: Insert the perform search variable, database search criteria,
results limit variables, and mgiSearchDatabase tag.
- A dynamic search page contains four distinct elements: 1) A variable
to initiate the dynamic search, 2) Variables to define the search criteria,
3) Variables to define the maximum number of results per page and 4) the
mgiSearchDatabase tag to define the database parameters and display of
search results.
-
- The "mgiSearchDatabaseAction=performSearch" variable initiates
the database search. Include the "mgiSearchDatabaseAction=performSearch"
variable using an mgiSet tag. The body of the set tag is ignored when this
variable is processed, therefore the text "MGI use only" is for
placement purposes only.
<mgiset name="mgiSearchDatabaseAction=performSearch">
MGI use only
</mgiset>
- Next use variables (mgiSet tags) to define the search criteria. In
the name of the mgiSet tag use the syntax "field=DatabaseFieldName"
where DatabaseFieldName is the name of the database field to search. In
the body of the mgiSet tag, enter the value to search for in the database
field. Database field names are case-sensitive. To display all records
in a field, enter an asterisk (*) as the value of the field. In this example,
a search for all records using the "Game Date" field is being
performed. Use multiple variables to perform "AND" searches.
That is, only records that match all search criteria are displayed.
<mgiset name="field=Game Date">
*
</mgiset>
- By default, search results are returned 25 per page. If you wish to
set a different results limit, include the mgiSearchDatabaseResultsLimit
and mgiSearchDatabaseTimeThru variables. Set the mgiSearchDatabaseResultsLimit
variable equal to the maximum number of results per page. In this example,
the maximum results per page is 50. Set the mgiSearchDatabaseTimeThru variable
equal to 1. In both results limit variables, enter the "MGI use only"
placeholder in the body of the mgiSet tags.
<mgiset name="mgiSearchDatabaseResultsLimit=50">
MGI use only
</mgiset>
<mgiset name="mgiSearchDatabaseTimeThru=1">
MGI use only
</mgiset>
- Finally, enter the mgiSearchDatabase tag, databaseFileLocation parameter,
tableName parameter, searchFormatFileLocation parameter, resultsFormatFileLocation
parameter, resultsTemplateFileLocation parameter, and orderByField parameter.
-
- In the databaseFileLocation parameter, enter the path to and the name
of the database file that contains the table of information to search.
In the tableName parameter, enter the name of the database table to search.
Note: one mgiSearchDatabase tag can only search the fields in one database
table. In the searchFormatFileLocation parameter, enter the name of the
text file that specifies the content and layout of the search form. In
the resultsFormatFileLocation parameter, enter the name of the text file
that specifies the layout of the results list. In the resultsTemplateFileLocation
parameter, enter the name of the text file that specifies the layout of
each result in the results list. In the orderByField parameter, enter the
name of the database field to use for ordering results. The database field
that you use to order results must be an indexed field (indexing is set
up when the field is created).
-
- The following are all of the elements of a dynamic search page.
<mgiset name="mgiSearchDatabaseAction=performSearch">
MGI use only
</mgiset>
<mgiset name="field=Game Date">
*
</mgiset>
<mgiset name="mgiSearchDatabaseResultsLimit=50">
MGI use only
</mgiset>
<mgiset name="mgiSearchDatabaseTimeThru=1">
MGI use only
</mgiset>
<mgiSearchDatabase databaseFileLocation="Baseball"
tableName="Games"
searchFormatFileLocation="blank.txt"
resultsFormatFileLocation="resultsformat.txt"
resultsTemplateFileLocation="resultstemplate.txt"
orderByField="Game Date">
Step 5: Save the dynamic search page.
- Save the changes you have made to the dynamic search page.
Step 6: Create a search format file in a text editor.
- For dynamic searches, the search format file is not parsed, but the
file must exist. Create a blank format file for the searchformatfile.
Step 7: Save the search format file.
- Save the search format file and name it "blank.txt", the
value of the searchFormatFile parameter in the mgiSearchDatabase tag on
the search page.
Step 8: Create a results format file in a text editor.
- Create a new page in a text editing program to specify the layout of
the results list. When the dynamic search page is parsed by MGI, the results
format file is included in the dynamic search page at the location of the
mgiSearchDatabase tag. The results format file should contain only HTML,
text, and MGI tags that are not repeated for each result. For example,
if your results are displayed in a table with a row of headers, the table
information and the first row of column labels might be included in the
results format file since you do not want a new table and header row for
each result that is displayed. However, depending on your layout, you could
include all of the results formatting information in the results template
file which specifies the layout of each result (e.g. if you wanted a new
table for each result that is displayed).
-
- Within the results format file, you must at least include the mgiSearchResults
variable. When the results format file is parsed by MGI, the results template
file that specifies the layout of each search result will appear in the
location of the mgiSearchResults variable.
<mgiGet name="mgiSearchResults">
- If it is possible to return more than 25 search results, you must
include the mgiPreviousButton and mgiNextButton variables in the results
format file. These variables create a "Previous" and "Next"
button to step through multiple screens of results.
<mgiGet name="mgiPreviousButton"> <mgiGet name="mgiNextButton">
- In the Little League Baseball example, the search results are displayed
between the beginning and ending table tags. The "Previous" and
"Next" buttons appear below the search results (the form actions
for the Previous and Next buttons are entered automatically by MGI). The
following is the complete results format file for the Little League Baseball
database:
<center>
<TABLE WIDTH="400" BORDER="0" CELLSPACING="0" CELLPADDING="3">
<TR>
<TH><P ALIGN=LEFT>Game Date</TH>
<TH COLSPAN="2">Teams</TH></TR>
<TR>
<TH> </TH>
<TH COLSPAN="2"> </TH></TR>
<mgiGet name="mgiSearchResults">
</TABLE>
</center>
<p><center><mgiGet name="mgiPreviousButton">
<mgiGet name="mgiNextButton"></center>
Step 9: Save the results format file.
- Save the results format file and name it "resultsformat.txt",
the value of the resultsFormatFile parameter in the mgiSearchDatabase tag
on the dynamic search page.
Step 10: Create a results template file in a text editor.
- Create a new page in a text editing program to specify the layout of
each result in the results list. The results template file should contain
HTML, text, and MGI tags to display database information for each result.
The entire format of the results template file is repeated for each result
(whether there are 2 or 20) and the database information for each result
is dynamically displayed. For example, in the Clothing database example,
the Description and Price are dynamically displayed for each clothing result.
-
- To include database information for each result in the results template
file, use the mgiGet tag syntax. The name of the mgiGet tag specifies the
database field information to display. Keep in mind that the database field
names are case-sensitive.
<mgiGet name="DatabaseFieldName">
- In the Little League Baseball database example, each result consists
of three table rows. In the table rows, the Game Time, Game Location, Home
Team, Visiting Team, Home Team Score, Visiting Team Score and Game Summary
are displayed. The following is the complete results template file for
the Little League Baseball database:
<TR>
<TD BGCOLOR="#ccffcc">
<B><mgiGet name="Game Date"></B> at <mgiGet name="Game Time"> in
<mgiGet name="Game Location"></TD>
<TD BGCOLOR="#ffffcc">
<center><mgiGet name="Home Team"></center></TD>
<TD BGCOLOR="#ffcccc">
<center><mgiGet name="Visiting Team"></center></TD></TR>
<TR>
<TH BGCOLOR="#ccffcc"><P ALIGN=RIGHT>Score</TH>
<TD BGCOLOR="#ffffcc">
<center><mgiGet name="Home Team Score"></center></TD>
<TD BGCOLOR="#ffcccc">
<center><mgiGet name="Visiting Team Score"></center></TD></TR>
<TR>
<TD COLSPAN="3"><mgiGet name="Game Summary"></TD></TR>
<TR>
<TD COLSPAN="3"> </TD></TR>
Step 11: Save the results template file.
- Save the results template file and name it "resultstemplate.txt",
the value of the resultsTemplateFile parameter in the mgiSearchDatabase
tag on the dynamic search page.
Step 12: FTP the dynamic search page, format files and template file
to the web server running MGI.
- Upload the dynamic search page, format files and template file to the
web server using an FTP program.
Step 13: View the dynamic search page in a browser.
- View the dynamic search page in a web browser. The search results are
displayed when the page is accessed.
|