fenway Posted September 14, 2009 Share Posted September 14, 2009 What was wrong with REPLACE()? TRIM() won't find embedded hyphens. Quote Link to comment https://forums.phpfreaks.com/topic/174156-solved-search-with-without-hyphen/page/2/#findComment-918233 Share on other sites More sharing options...
vinpkl Posted September 14, 2009 Author Share Posted September 14, 2009 Hi fenway both replace() and trim() are not removing hyphens from product_name while calling query. like if there is product name AC-3A and i enter keyword AC3A then while calling query the product name still remains AC-3A. Therefore both product name and keyword doesnt match and no result is found. vineet What was wrong with REPLACE()? TRIM() won't find embedded hyphens. Quote Link to comment https://forums.phpfreaks.com/topic/174156-solved-search-with-without-hyphen/page/2/#findComment-918236 Share on other sites More sharing options...
Zane Posted September 14, 2009 Share Posted September 14, 2009 What was wrong with REPLACE()? TRIM() won't find embedded hyphens. idk, I was glancing through the mysql doc on replace and though it was an actual command like SELECT or UPDATE, guess I was wrong...maybe this would work then SELECT * FROM product_table WHERE REPLACE(`product_name`,'-','') LIKE '%" . $keyword . "%' but if you did that you'd HAVE to strip the hyphen beforehand...AND the wildcards would be kind of redundant...depending on what you have in that field EDIT: or maybe... SELECT * FROM product_table WHERE REPLACE('".$keyword."','-','') LIKE REPLACE(`product_name`,'-','') Quote Link to comment https://forums.phpfreaks.com/topic/174156-solved-search-with-without-hyphen/page/2/#findComment-918237 Share on other sites More sharing options...
vinpkl Posted September 14, 2009 Author Share Posted September 14, 2009 hi zaus great solution. This time it did the trick. thanks a lot. vineet What was wrong with REPLACE()? TRIM() won't find embedded hyphens. idk, I was glancing through the mysql doc on replace and though it was an actual command like SELECT or UPDATE, guess I was wrong...maybe this would work then SELECT * FROM product_table WHERE REPLACE(`product_name`,'-','') LIKE '%" . $keyword . "%' but if you did that you'd HAVE to strip the hyphen beforehand...AND the wildcards would be kind of redundant...depending on what you have in that field EDIT: or maybe... SELECT * FROM product_table WHERE REPLACE('".$keyword."','-','') LIKE REPLACE(`product_name`,'-','') Quote Link to comment https://forums.phpfreaks.com/topic/174156-solved-search-with-without-hyphen/page/2/#findComment-918241 Share on other sites More sharing options...
Zane Posted September 14, 2009 Share Posted September 14, 2009 you should just use = instead of LIKE since of course you're not using any wildcards....and it works Quote Link to comment https://forums.phpfreaks.com/topic/174156-solved-search-with-without-hyphen/page/2/#findComment-918243 Share on other sites More sharing options...
vinpkl Posted September 14, 2009 Author Share Posted September 14, 2009 thanks zanus your both solutions works great. vineet you should just use = instead of LIKE since of course you're not using any wildcards....and it works Quote Link to comment https://forums.phpfreaks.com/topic/174156-solved-search-with-without-hyphen/page/2/#findComment-918257 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.