2016-07-02 3 views
0

私は最近、仕事のためにウェブサイトを構築しました。なぜなら私たちの技術者は、私たちがサービスを提供するプロパティにどのようなキーが行くのかを簡単に知る必要があるからです。私はライブサーチ(Ajaxlivesearch.com)を使ってサイトを稼働させ、それは自分のMySQLデータベースにリンクしています。現在は1つの列、つまりAddress列のみを検索する以外はすべて機能します。 AddressProperty_Nameの2つの列を同時に検索できるようにしたいと考えています。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' => array( 'Address' AND 'Property_Name')を試してみましたが、両方の列を検索すると思っても動作しませんでした。

答えて

0

私はAjaxlivesearchに慣れていないんだけど、searchColumnsはそう、配列をとるように見えます:

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

はおそらく動作します。

array('Address' AND 'Property_Name')は構文エラーになります。)

+0

ありがとうございました!私は文字通りそれを理解して答えを更新するためにここに戻ってきました。そして、あなたは正しく答えたことが分かりました。 –

0

そしてもちろん、すぐに私はそれを把握する質問を投稿すると、多分それはしかし他の誰かを助けます。あなたはカンマ(、)作業コードでそれらを分離する必要がある1つのアレイに複数の列を見るためには次のとおりです。

<?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

関連する問題