title: how to count the matched keywords using select in mysql codeigniter php?
body: <p>how to count the matched keywords using select in mysql codeigniter php? here is my table</p>
  
  <p>Ex. assuming that the search keywords are yes, test</p>
  
  <pre><code>messages table
  
  id | title     | msg               |date
  ---+-----------+-------------------+-------------+--      
  1  |  test1    |  yes              | 2016-06-01 // 2 match keywords
  2  |  yes1     |  no               | 2016-06-02 // 1 match keywords   
  3  |  test2    |  no               | 2016-06-03 // 1 match keywords
  4  |  yes2     |  yes yes yes      | 2016-06-04 // 4 match keywords
  5  |  yesyes3  |  yes yes yes yes  | 2016-06-05 // 6 match keywords
  </code></pre>
  
  <p>now need to display it with count_match column</p>
  
  <pre><code>id | title     | msg               |date        |count_match    
  ---+-----------+-------------------+------------+-------------------    
  1  |  test1    |  yes              | 2016-06-01 | 2
  2  |  yes1     |  no               | 2016-06-02 | 1  
  3  |  test2    |  no               | 2016-06-03 | 1
  4  |  yes2     |  yes yes yes      | 2016-06-04 | 4
  5  |  yesyes3  |  yes yes yes yes  | 2016-06-05 | 6
  </code></pre>
  
  <p>and for array it should displayed look like this</p>
  
  <pre><code>array (
      [0] =&gt; array (
          [id] =&gt; 5
          [title] =&gt; yesyes3
          [msg] =&gt; yes yes yes yes
          [date] =&gt; 2016-06-05
          [match] =&gt; 6
      )
      [1] =&gt; array (
          [id] =&gt; 4
          [title] =&gt; yes2
          [msg] =&gt; yes yes yes
          [date] =&gt; 2016-06-04
          [match] =&gt; 4
      )
      [2] =&gt; array (
          [id] =&gt; 1
          [title] =&gt; test1
          [msg] =&gt; yes
          [date] =&gt; 2016-06-01
          [match] =&gt; 2
      )
      [3] =&gt; array (
          [id] =&gt; 3
          [title] =&gt; test2
          [msg] =&gt; no
          [date] =&gt; 2016-06-03
          [match] =&gt; 1
      )
      [4] =&gt; array (
          [id] =&gt; 2
          [title] =&gt; yes1
          [msg] =&gt; no
          [date] =&gt; 2016-06-02
          [match] =&gt; 1
      )
  )
  </code></pre>
  
  <p>and currently my code in fetching for this is this</p>
  
  <pre><code>        $match = array('test','yes');
          $orderbyString1 = "";
          $orderbyString = "";
          $likestr = "";
          foreach($match AS $value)
          {
              $orderbyString .= "IF(m.title LIKE '%".$value."%' OR m.msg LIKE '%".$value."%',1,0)+";
              $likestr .= "m.title LIKE '%".$value."%' OR m.msg LIKE '%".$value."%' OR ";
          }
          $orderbyString = substr($orderbyString, 0, -1);
          $likestr = substr($likestr, 0, -4);
          $this-&gt;db-&gt;select('m.*, ('.$orderbyString.') as count_match');
          $this-&gt;db-&gt;from('messages m');
          $this-&gt;db-&gt;where($likestr." ORDER BY ".$orderbyString." DESC");
  
          $query = $this-&gt;db-&gt;get();
  
          $results = $query-&gt;result_array();
          print_r($results);exit;
  </code></pre>
  
  <p>Is there any way for the select to display the correct count_match using php codeigniter code? because currently it displays 1 and 2 under count_match.</p>
  
  <p>Thanks!</p>