dimports Posted May 22, 2005 Share Posted May 22, 2005 (edited) I am very suprised that oscommerce didnt come with a 'not' option in the search module. Only 'and' and 'or' and parenthesis. I'm trying to hack the search file to include 'not'. As now, when i search for lion, results of stallion also mixes in my search result. So I want to do 'lion not stallion' to get only lions. This is the section I think the hack takes place in advance_search_result.php: ? ?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; ? ? ? ?case 'not': ? ? ? ? ?$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 .= ")"; ?} If you notice, I copied the 'or' section and just replaced it with 'not'. This is the problem I get: 1064 - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'and (pd.products_name like '%stallion%' or p.products_model lik select count(distinct p.products_id) as total from products p left join manufacturers m using(manufacturers_id), products_description pd left join specials s on p.products_id = s.products_id, categories c, products_to_categories p2c where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '1' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and ((pd.products_name like '%lion%' or p.products_model like '%lion%' or m.manufacturers_name like '%lion%') and not and (pd.products_name like '%stallion%' or p.products_model like '%stallion%' or m.manufacturers_name like '%stallion%')) Why does it automatically put an 'and' before not and after it. It doesn't do that with the 'or'. I know that in the keywords, spaces are converted to 'and', but these ands are out of place. Please help because its driving me nuts! Thanks in advance to all. Edited May 22, 2005 by dimports Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.