Reusing the Search Class
Reusing the Search Class
The HRDIODB search class was written with reuse in mind. This
tutorial will show you how to use the HRDIODB search class in your
project to access data from the HRDI database.
Written by Ziba R. Scott
and Adam D. Gorski
Table of Contents
Required classes
The search class depends upon the hrdi_db class which
requires and is a child class of the mcpear class. Your project
must have access to each of these three classes by including the following
files:
Optionally, you may be interested in including the debugging debugging.php
file for convenience functions.
Create the class instances
The search class is related to the hrdi_db class by
composition and requires it as an argument to the constructor. The hrdi_db
class requires a DSN as an argument to its constructor. A DSN is
the "Data Source Name" which is of the format:
phptype(dbsyntax)://username:password@protocol+hostspec/database
or more simply: phptype://username:password@hostspec.
You can either write your own DSN variable, copy the variable from conf.php
or include conf.php. Including conf.php will put
all the variables from conf.php into your global name space.
/* HRDI configuration file */
require_once("conf.php");
/* HRDI specific database interface */
require_once("hrdi_db_class.php");
/* HRDI specific search methods */
require_once("search_class.php");
Using the free_form() method
search::free_form() is a very useful search method which takes a specially
formatted associative array and performs a query based on it. When search::free_form()
is called, the query is performed and the results are put in
$search->results. For information about using other
search methods see Writing New Predefined Searches.
$conditions[0]["Table"]="HRDI_Days";
$conditions[0]["Field"]="UARS_Day";
$conditions[0]["Operator"]="<";
$conditions[0]["Value"]="30";
$conditions[1]["Table"]="HRDI_Days";
$conditions[1]["Field"]="Flight_Direction";
$conditions[1]["Operator"]="=";
$conditions[1]["Value"]="Backward";
$status = $search->free_form($conditions);
Accessing the search results
Search functions populate the $search->results variable
with an indexed array of UARS Days
// After free_form has been called we can print a list of Days that matched
foreach($search->results as $day){
print "$day<br>";
}
From here you can perform your own actions on the days you have retrieved.
If you wish to take advantage of the uars_day class for retrieving
more information about a specific day, see {@tutorial
using_search_class.pkg}.