Senthilkumar
Senthilkumar

Reputation: 100

Multiple conditions in LIKE operator

i am getting multiple values in this $languages like(php,Ruby) i want spilt that and how to check that split values in this query

SELECT * FROM software_capability where languages LIKE '%$languages%'

Upvotes: 0

Views: 208

Answers (4)

Akg
Akg

Reputation: 359

As in other languages Mysql also supports regexp for pattern matching that could be used in such cases. I would simply create a query string separated by the delimiter (|) out of the $languages array, and use that in the query --

$query_string = implode("|", $languages);
SELECT * FROM software_capability where languages REGEXP $query_string

The result will be same using LIKE clause as given in other answer.

Upvotes: 1

sarwar026
sarwar026

Reputation: 3821

If $languages is comma (,) separated values, then you can try with IN command of mysql

SELECT * FROM software_capability where languages IN ($languages)

Upvotes: 0

m-farhan
m-farhan

Reputation: 1426

Try with this.

 SELECT * FROM table WHERE interests LIKE ('%sports%', '%pub%')

This is syntax. Exploded your $language and put each item in '%$item%'

Upvotes: 0

Chanon
Chanon

Reputation: 476

SELECT * FROM software_capability where CONCAT('%',languages,'%') LIKE '$languages';

assuming that $languages is 'php,Ruby'

Upvotes: 0

Related Questions