Home arrow PHP arrow Page 2 - Creating a Searchable Inventory System: Setting Up Your Database and User Interface (continued)

Helper Search Class - PHP

In this second part of an article about setting up a searchable inventory system, we will cover our helper Search class, and some of the things this class will need to be able to do.

TABLE OF CONTENTS:
  1. Creating a Searchable Inventory System: Setting Up Your Database and User Interface (continued)
  2. Helper Search Class
  3. Our First Helper Search Function
  4. Dynamic SELECT Menus
By: Brian Vaughn
Rating: starstarstarstarstar / 9
November 15, 2005

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

To start things off, our search.php file should contain the following:

<?php
class search {

      function get_search_field( $p_search_field_name ) {
            $r_html     = NULL;           

            # return HTML
            return $r_html;           

      } # END get_search_field()

     } # END class search
?>

The next step is to think about the information this function will need in order to operate properly. First, it will need to know the type of form field we wish to create (SELECT menu or text input). If we wish to create a SELECT menu, it will also require some additional information, such as the SQL query needed to retrieve a list of SELECT options. Since we are creating several of these select menus to depend on another menu, we will also need to tell the “get_search_field” function whether a field is dependent upon itself, or another field.

This can all be done through the use of associative arrays. Furthermore, our “inc.conf.php” file is a great place to do all of this, so let’s go ahead and set up the arrays by adding the following code:

# configure various search fields
# first, instantiate over-all search array
$search_array                             = array();

# configure and append categories array
$categories_array                         = array();
$categories_array['field_type']           = 'select';
$categories_array['populate_query']       = 'SELECT id AS value,
name AS display FROM pc_categories ORDER BY name ASC;';
$categories_array['parent_menu']          = NULL;
$categories_array['html_attributes']      = 'onChange="attach_file( \'helper.php?category_id=\' +
this.options[ this.selectedIndex ].value );"';

# configure and append sub categories array
$sub_categories_array                     = array();
$sub_categories_array['field_type']       = 'select';
$sub_categories_array['populate_query']   = 'SELECT id AS value,
name AS display FROM pc_sub_categories WHERE category_id =
<<field>> ORDER BY name ASC;';
$sub_categories_array['parent_menu']      = 'Categories';
$sub_categories_array['html_attributes']  = NULL;

# configure and append manufacturers array
$manufacturers_array                      = array();
$manufacturers_array['field_type']        = 'select';
$manufacturers_array['populate_query']    = 'SELECT id AS value,
name AS display FROM pc_manufacturers WHERE category_id =
<<field>> ORDER BY name ASC;';
$manufacturers_array['parent_menu']       = 'Categories';
$manufacturers_array['html_attributes']   = NULL;

# configure and append keywords array
$keywords_array                           = array();
$keywords_array['field_type']             = 'text';
$keywords_array['parent_menu']            = NULL;
$keywords_array['populate_query']         = NULL;
$keywords_array['html_attributes']        = NULL;

# add each field to main search array
$search_array['Categories']               = $categories_array;
$search_array['Sub Categories']           = $sub_categories_array;
$search_array['Manufacturers']            = $manufacturers_array;
$search_array['Keywords']                 = $keywords_array;

# set search array to be global
$GLOBALS['search_array']                  = $search_array;

As you can see, we have created a GLOBAL array, “search_array”, and added within that array several other arrays –- each describing a particular field of our search form. Each field for instance specifies a “file_type”, either “select” or “text”. If the field is of type “select” then the array also specifies the query that will be required to retrieve a list of all possible SELECT values, and so forth. We’ll take a closer look at each of these elements as we create our helper Search class, which we are now ready to start on.



 
 
>>> More PHP Articles          >>> More By Brian Vaughn
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: