2014-02-21 08:17
浏览 92


I have an issue that I am stuck in,

I have a table called wpg_original_word with field tags, which contains comma separated values and what I want to achieve is search for tags which are starting with the letter 'd'

I have written the query

SELECT DISTINCT tags FROM wpg_original_word  WHERE tags LIKE 'd%' ;

It returns the whole string like 'Diabetes, Nutrition, Dietician' , but I want only the Diabetes, Dietician.

Any help?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dsfgdsjfd78773
    dsfgdsjfd78773 2014-02-21 08:32

    You could split the string with PHP, use the following code

    $string = 'Diabetes, Nutrition, Dietician';
    $array = explode(',', $string);
    $result = array();
    foreach ($array as $part) {
        if (substr(strtolower(trim($part)),0,1) == 'd') {
            array_push($result, trim($part));

    See it in action here.

    点赞 评论
  • dongluan6784
    dongluan6784 2014-02-21 08:26

    You can use in_array() to check for a string in your query and then print it.

    点赞 评论