I'm trying to search some fields for complete words. The word can be in the middle of a string of text. My solution (perhaps there is a better one) is to use the following query:
Expand|Select|Wrap|Line Numbers
- SELECT id, string FROM string_table WHERE string LIKE ('%This is my very long test string%') OR string LIKE ('% This %') OR string LIKE ('% very %') OR long LIKE ('% long %') OR test LIKE ('% test %') OR string LIKE ('% string %');
My problem arises when I send this query using PHP. I use something like this:
Expand|Select|Wrap|Line Numbers
- $output=array();
- $query= "SELECT id, string FROM string_table WHERE string LIKE ('%This is my very long test string%') OR string LIKE ('% This %') OR string LIKE ('% very %') OR long LIKE ('% long %') OR test LIKE ('% test %') OR string LIKE ('% string %')";
- $result= mysql_result($query,$link);
- if ($result && mysql_num_rows($result)>0) {
- while ($row=mysql_fetch_array($result)) {
- $output=$row;
- }
- }
- var_dump($output);
I think it's something to do with character encoding but I'm not really familiar with how to get PHP to send the query in the correct format so that the spaces are retained.
Can anyone help me?
Thanks!