View Single Post
  #5 (permalink)  
Old 06-19-2007, 08:48 AM
curtiss's Avatar
curtiss curtiss is offline
Moderator
 
Join Date: May 2003
Posts: 1,468
Okay. First of all, you need to develop your form correctly. Here are some tips, which I will use when I show you the PHP code you will need:
  1. Your input names should never have spaces in them. For instance, "Item Number" should actually be named something like "ItemNumber" or "item_number" or something similar.
  2. Always assign an ID to your form elements. When using PHP, you can actually leave out the "name" altogether, and just use the ID. With ASP, you are required to use the name. With JavaScript, the name is the more conventional way of doing things, but you can get everything accomplished using the ID. ID's should always be unique. No item can ever have exactly the same ID as another item.
  3. Make sure you assign a name and ID to your "Search" button.
  4. Wrap each of your form element labels in <label> tags. For instance, rather than using:
    Code:
    <b>Item Number:</b>
    you should use
    Code:
    <label>Item Number:</label>
    You can then use CSS to make your labels bold.
  5. When using select elements, radio buttons or checkboxes with PHP, you will need to add opening and closing square brackets to the names of your form elements. In other words, the name of your second form element should be "color[]" instead of just "color". This tells PHP that this might be an array.
  6. In order to save hassles, make sure that your SQL table columns have the same names as your form elements. In other words, if you have a column in your table called "ItemNum", then your matching form element should be called "ItemNum".

Now, your PHP should look something like:
PHP Code:
if($_POST[btn_search] == "Search") {
    
$mySearchItems = array("item_number","color","description","page");
    
$sql_array = array();
    
$i 0;
    foreach(
$mySearchItems as $term) {
        if(!empty(
$_POST[$term])) {
            if(
is_array($_POST[$term])) {
                
$_POST[$term] = join($_POST[$term]," OR `$term` = ";
            }
            
$sql_array[$i] = " (`$term` = '$_POST[$term]')";
            
$i++;
        }
    }
    
$sql "SELECT * FROM `CatalogItems` WHERE".join($sql_array" AND")." ORDER BY `item_number` ASC";
    
$sql mysql_query($sql$link);
    while(
$rs mysql_fetch_array($sql)) {
        
$catalog_echo .= "
        <div class='result_line'>"
;
        foreach(
$mySearchItems as $term) {
            
$catalog_echo .= "
            <div class='result_item'>$rs[$term]</div>"
;
        }
        
$catalog_echo .= "
        </div>"
;
    }

That will get you started on the PHP end of it. The SQL end of it is pretty simple once you find a place to set up a development database.

There is only one thing left to add to the PHP code, which would be to set up partial matching on the item number. It's very simple to do, but we'll work on that once we make sure that the PHP I showed you above will work for you.
__________________
I hate Internet Explorer! Anyone with me?
Reply With Quote