Page List search with number is not correct

Permalink
Hi all, I'm having a problem to search for products by its keywords.
Here a little code:
public function view() {
$productList = new PageList();
      $productList->sortByDisplayOrder();
      if (!empty($_GET['cKeyword']) && $q = trim($_GET['cKeyword'])) {
         $productList->filterByKeywords($q);
      }
$productList->setItemsPerPage(10);
      $this->set('productList', $productList);
      $this->set('productResults', $productList->getPage());
   }


This works fine when I enter a "string" (like "C8000", which is a product name), but the search result is empty when keyword is a number (like "8000"). : -(

Any recommendations?

 
jordanlev replied on at Permalink Best Answer Reply
jordanlev
It's possible that the ADODB library (which handles database querying for C5) is interpreting the number as if it's a number field in the database and not escaping it properly... you might want to try replacing the "$productList->gilterByKeywords" line with this:
$productList->filter(false, "ak_keywords LIKE '%" . Loader::db()->escape($q) . "%'");

(This assumes you have a page attribute with the handle "keywords", and that it's a textbox type -- not a "select" type attribute).