Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing php code for searching 1

Status
Not open for further replies.

keepingbusy

Programmer
Apr 9, 2000
1,470
0
0
GB
I have some coding used in an oscommerce site and I have been looking at the \advanced_search.php and \advanced_search_results.php in an effort to establish how I can get the coding to give someone an exact match when they search for a particular product. I have found this section in \advanced_search_results.php which I think may be the part that needs changing:
Code:
  if (isset($search_keywords) && (sizeof($search_keywords) > 0)) {
    $where_str .= " and (";
    for ($i=0, $n=sizeof($search_keywords); $i<$n; $i++ ) {
      switch ($search_keywords[$i]) {
        case '(':
        case ')':
        case 'and':
        case 'or':
          $where_str .= " " . $search_keywords[$i] . " ";
          break;
        default:
          $keyword = tep_db_prepare_input($search_keywords[$i]);
          $where_str .= "(pd.products_name like '%" . tep_db_input($keyword) . "%' or p.products_model like '%" . tep_db_input($keyword) . "%' or m.manufacturers_name like '%" . tep_db_input($keyword) . "%'";
          if (isset($HTTP_GET_VARS['search_in_description']) && ($HTTP_GET_VARS['search_in_description'] == '1')) $where_str .= " or pd.products_description like '%" . tep_db_input($keyword) . "%'";
          $where_str .= ')';
          break;
      }
    }
    $where_str .= " )";
  }
What I am trying to achieve is when someone types in a description, for example: HILLSIDE it will search and return all records that only = the word HILLSIDE which is in the table PRODUCTS and field PRODUCTS_MODEL

Anything else is ignored. So if there are records such HILLSIDE COUNTY these will be ignored.

As a FoxPro programmer I know the command:
Code:
SELECT * FROM PRODUCTS WHERE COLUMN3 LIKE "HILLSIDE"
will produce the desired effect, but not sure how this is done in php.

Before I start removing any of the php code, I would appreciate any help or guidance.

Many thanks

Windows Vista
Visual FoxPro Versions 6 & 9
 
just remove the % signs from the code.
although this will search products_name, manufacturers_name and products model. to change this to just products_name edit as shown

Code:
$where_str .= "(pd.products_name like '%" . tep_db_input($keyword) . "%' [red]"; //[/red]or p.products_model like '%" . tep_db_input($keyword) . "%' or m.manufacturers_name like '%" . tep_db_input($keyword) . "%'";
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top