HRDIODB
[ class tree: HRDIODB ] [ index: HRDIODB ] [ all elements ]
Prev Next
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.

  1. /* HRDI configuration file */
  2. require_once("conf.php");
  3. /* HRDI specific database interface */
  4. require_once("hrdi_db_class.php");
  5. /* HRDI specific search methods */
  6. require_once("search_class.php");
  7.  
  8. $hdb new hrdi_db($dsn);
  9. $search new search($hdb);

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.

  1. $conditions[0]["Table"]="HRDI_Days";
  2. $conditions[0]["Field"]="UARS_Day";
  3. $conditions[0]["Operator"]="<";
  4. $conditions[0]["Value"]="30";
  5.  
  6. $conditions[1]["Table"]="HRDI_Days";
  7. $conditions[1]["Field"]="Flight_Direction";
  8. $conditions[1]["Operator"]="=";
  9. $conditions[1]["Value"]="Backward";
  10.  
  11. $status $search->free_form($conditions);

Accessing the search results

Search functions populate the $search->results variable with an indexed array of UARS Days

  1. // After free_form has been called we can print a list of Days that matched 
  2. foreach($search->results as $day){
  3.   print "$day<br>";
  4. }

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}.


Prev   Next
HRDI Observational Database Documentation

Documentation generated on Tue, 23 Jan 2007 22:57:42 -0500 by phpDocumentor 1.3.0RC6