How to search "tags" in MySQL? -


if have table on db called product_tags 2 fields: tag_id , tag_name

here schema:

create table `product_tags` (  `tag_id` int(11) not null auto_increment,  `tag_name` varchar(255) not null,  primary key  (`tag_id`),  unique key `tag_name` (`tag_name`) ) engine=myisam auto_increment=84 default charset=utf8 

say here tags in it:

  • yellow gold
  • yellow diamond
  • white gold
  • rose gold
  • band
  • diamond
  • blue diamond
  • pink diamond
  • black diamond

and want search on string "yellow gold diamond band"

i want pull following tags:

  • yellow gold
  • band
  • diamond

because tags in string. yellow , diamond both in string not yellow diamond tag should ignored.


-additionally if possible

if did search "yellow gold blue diamond band"

i want pull following tags:

  • yellow gold
  • band
  • blue diamond

the diamond tag ignored because blue diamond tag match.


how can this?

edit:

select    *     product_tags p    instr('yellow gold diamond band', p.tag_name) > 0 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -