title: Retrieve MYSQL field array with "Like"
body: <p>I have pages saved in mysql db, and one of the fields is an array of tags, for each page, which was in hopes to help with a site search. </p>
  
  <p>I'm getting an error which is caused by my call...</p>
  
  <pre><code>$results = $db-&gt;select('pages','','','name',array('name', 'DESC'),'10',array('tags', '%' .$word. '%'));
  </code></pre>
  
  <p>(the select works as -- 'table','where','bind for where query match','fields','orderby array','limit',where/like array')</p>
  
  <p>I think the problem is lying in the 'tags' field being an array. What is the best way to go about this? If necessary, I'm pulling each result up as so after the query:</p>
  
  <pre><code>//if we got something through $_POST
  if (isset($_GET['search'])) {
  // here you would normally include some database connection
  require_once('../config/dbconfig.php');
  
  // never trust what user wrote! We must ALWAYS sanitize user input
  //$word = mysql_real_escape_string($_POST['search']);
  $word = htmlentities($_GET['search']);
  // build your search query to the database
  //$sql = "SELECT title, url FROM pages WHERE content LIKE '%" . $word . "%' ORDER BY title LIMIT 10";
  
  $results = $db-&gt;select('pages','','','*',array('name', 'DESC'),'10',array('tags', '%' .$word. '%'));
  
  // get results
  if (count($results) &gt; 0) {
      $end_result = '';
      echo '&lt;ul&gt;';
      foreach($results as $row) {
          $bold = '&lt;span class="found"&gt;' .$word. '&lt;/span&gt;';
          $end_result .= '&lt;li&gt;' .str_ireplace($word, $bold, $row['title']).   '&lt;/li&gt;';
      }
      //echo $end_result. '&lt;/ul&gt;';
  }else {
      //echo '&lt;ul&gt;&lt;li&gt;No results found&lt;/li&gt;&lt;/ul&gt;';
  }
  var_dump($results);
  exit;
  }
  </code></pre>
  
  <p>It says the error is in my foreach:</p>
  
  <blockquote>
    <p>Warning: Invalid argument supplied for foreach()</p>
  </blockquote>
  
  <p>which every time so far has been because of my query before it. Every single time. </p>
  
  <p>I searched and didn't see anything specifically like this, if I missed it I'm very sorry. Also I'm tired, so if I missed some details let me know and I will post them. Thanks!</p>
  
  <p>This is how the select is processing before it hits run.</p>
  
  <pre><code>public function select($table, $where="", $bind="", $fields="*", $order="", $limit="", $like="") {
      $sql = "SELECT " . $fields . " FROM " . $table;
      if(!empty($where)) {
          $sql .= " WHERE " . $where;
      }
      if (!empty($order)) {
          $sql .= " ORDER BY " . $order[0] . " " . $order[1];
      }
      if (!empty($limit) &amp;&amp; is_array($limit)) {
          $sql .= " LIMIT " . $limit[0] . " " . $limit[1];
      }
      if (!empty($limit)) {
          $sql .= " LIMIT " . $limit;
      }
      if (!empty($like)) {
          $sql .= " WHERE " .$like[0]. " LIKE " . $like[1];
      }
      $sql .= ";";
      //var_dump($sql);
      //var_dump($bind);
      //exit;
      return $this-&gt;run($sql, $bind);
  }
  
  public function run($sql, $bind="") {
      $this-&gt;sql = trim($sql);
      $this-&gt;bind = $this-&gt;cleanup($bind);
      $this-&gt;error = "";
  
      try {
          $pdostmt = $this-&gt;prepare($this-&gt;sql);
          if($pdostmt-&gt;execute($this-&gt;bind) !== false) {
              if(preg_match("/^(" . implode("|", array("select", "describe", "pragma")) . ") /i", $this-&gt;sql))
                  return $pdostmt-&gt;fetchAll(PDO::FETCH_ASSOC);
              elseif(preg_match("/^(" . implode("|", array("delete", "insert", "update")) . ") /i", $this-&gt;sql))
                  return $pdostmt-&gt;rowCount();
          }   
      } catch (PDOException $e) {
          $this-&gt;error = $e-&gt;getMessage();    
          $this-&gt;debug();
          return false;
      }
  }
  </code></pre>
  
  <p>(switched to $_GET b/c the search is using AJAX and didn't feel like changing a bunch of stuff just to call it, so did it directly in the page with the url instead.)</p>
  
  <p>nm on that query edit i just removed, it was right the first time... tired sorry...</p>