Jump to content

[SOLVED] search with without hyphen


vinpkl

Recommended Posts

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.

Link to comment
Share on other sites

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`,'-','')

Link to comment
Share on other sites

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`,'-','')

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.