2

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?

Rakesh KR
  • 6,357
  • 5
  • 40
  • 55
Vidya L
  • 2,289
  • 4
  • 27
  • 42

2 Answers2

3

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

<?php

$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));
    }
}

var_dump($result);

See it in action here. http://codepad.org/SVk7FPx9

Tuim
  • 2,491
  • 1
  • 14
  • 31
0

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

Gottlieb Notschnabel
  • 9,408
  • 18
  • 74
  • 116
user986959
  • 620
  • 2
  • 7
  • 22