2016-07-02 14 views
0

Недавно я создал веб-сайт для работы, потому что нашим техническим специалистам нужен простой способ узнать, какие ключи идут на какие свойства мы предоставляем. Я получил сайт, работающий с поиском в реальном времени (Ajaxlivesearch.com), и он связан с моей базой данных MySQL. Все работает отлично, за исключением того, что он ищет только один столбец в настоящее время, столбец Address. Я хотел бы иметь возможность искать две колонки: Address и Property_Name одновременно.Как указать несколько столбцов для поиска с помощью PHP?

Вот текущий код или, по крайней мере, часть, которая занимается поиском db.

<?php 

namespace AjaxLiveSearch\core; 

if (count(get_included_files()) === 1) { 
    exit('Direct access not permitted.'); 
} 

/** 
* Class Config 
*/ 
class Config 
{ 
    /** 
    * @var array 
    */ 
    private static $configs = array(
     // ***** Database ***** // 
     'dataSources'   => array(
      'ls_query' => array(
       'host'    => '', 
       'database'   => '', 
       'username'   => '', 
       'pass'    => '', 
       'table'    => '', 
       // specify the name of search columns 
       'searchColumns'  => array('Address'), 
       // specify order by column. This is optional 
       'orderBy'   => '', 
       // specify order direction e.g. ASC or DESC. This is optional 
       'orderDirection'  => '', 
       // filter the result by entering table column names 
       // to get all the columns, remove filterResult or make it an empty array 
       'filterResult'  => array(), 
       // specify search query comparison operator. possible values for comparison operators are: 'LIKE' and '='. this is required. 
       'comparisonOperator' => 'LIKE', 
       // searchPattern is used to specify how the query is searched. possible values are: 'q', '*q', 'q*', '*q*'. this is required. 
       'searchPattern'  => 'q*', 
       // specify search query case sensitivity 
       'caseSensitive'  => false, 
       // to limit the maximum number of result uncomment this: 
       'maxResult' => 10, 
       // to display column header, change 'active' value to true 
       'displayHeader' => array(
        'active' => true, 
        'mapper' => array(
         'Property_Name' => 'Property Name', 
         'Address' => 'Address', 
         'Key' => 'Key', 
         'Property_Manager' => 'Property Manager', 
         'Door_Code' => 'Door Code' 
        ) 
       ), 
       // add custom class to <td> and <th> 
       // To hide a column use class 'ls_hide' 
       'columnClass' => array(
        'Count' => 'ls_hide', 
        'Reserve' => 'ls_hide' 
       ), 
       'type'    => 'mysql', 
      ), 

Я получил информацию о подключении по понятным причинам.

Я попробовал массив «searchColumns» => ('Address' AND 'Property_Name'), думая, что будет искать оба столбца, но это не работает вообще.

ответ

0

Я не знаком с Ajaxlivesearch, но это выглядит как searchColumns принимает массив, так:

'searchColumns' => array('Address', 'Property_Name'), 

вероятно, будет работать.

(array('Address' AND 'Property_Name') ошибка синтаксиса.)

+0

Спасибо! Я буквально просто вычислил это и вернулся сюда, чтобы обновить ответ, и теперь я вижу, что вы правильно ответили. –

0

И, конечно же, как только я отправляю вопрос, я понять это, может быть, это поможет кому-то еще, хотя. Для того, чтобы посмотреть на несколько столбцов в одном массиве необходимо разделить их запятыми (,) рабочий код:

<?php 
 

 
namespace AjaxLiveSearch\core; 
 

 
if (count(get_included_files()) === 1) { 
 
    exit('Direct access not permitted.'); 
 
} 
 

 
/** 
 
* Class Config 
 
*/ 
 
class Config 
 
{ 
 
    /** 
 
    * @var array 
 
    */ 
 
    private static $configs = array(
 
     // ***** Database ***** // 
 
     'dataSources'   => array(
 
      'ls_query' => array(
 
       'host'    => '', 
 
       'database'   => '', 
 
       'username'   => '', 
 
       'pass'    => '', 
 
       'table'    => '', 
 
       // specify the name of search columns 
 
       'searchColumns'  => array('Address', 'Property_Name'), 
 
       // specify order by column. This is optional 
 
       'orderBy'   => '', 
 
       // specify order direction e.g. ASC or DESC. This is optional 
 
       'orderDirection'  => '', 
 
       // filter the result by entering table column names 
 
       // to get all the columns, remove filterResult or make it an empty array 
 
       'filterResult'  => array(), 
 
       // specify search query comparison operator. possible values for comparison operators are: 'LIKE' and '='. this is required. 
 
       'comparisonOperator' => 'LIKE', 
 
       // searchPattern is used to specify how the query is searched. possible values are: 'q', '*q', 'q*', '*q*'. this is required. 
 
       'searchPattern'  => 'q*', 
 
       // specify search query case sensitivity 
 
       'caseSensitive'  => false, 
 
       // to limit the maximum number of result uncomment this: 
 
       'maxResult' => 10, 
 
       // to display column header, change 'active' value to true 
 
       'displayHeader' => array(
 
        'active' => true, 
 
        'mapper' => array(
 
         'Property_Name' => 'Property Name', 
 
         'Address' => 'Address', 
 
         'Key' => 'Key', 
 
         'Property_Manager' => 'Property Manager', 
 
         'Door_Code' => 'Door Code' 
 
        ) 
 
       ), 
 
       // add custom class to <td> and <th> 
 
       // To hide a column use class 'ls_hide' 
 
       'columnClass' => array(
 
        'Count' => 'ls_hide', 
 
        'Reserve' => 'ls_hide' 
 
       ), 
 
       'type'    => 'mysql', 
 
      ), 
 
Run code snippetCopy snippet to answer

Смежные вопросы