2016-07-02 3 views
0

Ich habe vor Kurzem eine Website für die Arbeit erstellt, weil unsere Techniker einen einfachen Weg brauchen, um herauszufinden, welche Schlüssel zu welchen Eigenschaften führen. Ich habe die Website mit Live-Suche (Ajaxlivesearch.com) arbeiten und es ist mit meiner MySQL-Datenbank verknüpft. Alles funktioniert gut, außer dass es nur eine Spalte aktuell durchsucht, die Spalte Address. Ich möchte in der Lage sein, zwei Spalten, Address und Property_Name gleichzeitig zu suchen.Wie kann ich mehrere Spalten angeben, die mit PHP durchsucht werden sollen?

Hier ist der aktuelle Code, oder zumindest der Teil, der mit der Suche nach der db befasst.

<?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', 
      ), 

Ich habe die Verbindungsinformationen aus offensichtlichen Gründen herausgenommen.

Ich versuchte 'searchColumns' => Array ('Adresse' AND 'Property_Name'), dachte, dass würde beide Spalten suchen, aber das hat überhaupt nicht funktioniert.

Antwort

0

Ich bin mit Ajaxlivesearch nicht vertraut, aber es sieht aus wie searchColumns ein Array nimmt, so:

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

wird wahrscheinlich funktionieren.

(array('Address' AND 'Property_Name') ist ein Syntaxfehler.)

+0

Thank you! Ich habe es buchstäblich herausgefunden und kam hierher zurück, um die Antwort zu aktualisieren und jetzt sehe ich, dass du auch richtig geantwortet hast. –

0

Und natürlich, sobald ich die Frage, die ich es posten herauszufinden, vielleicht wird es wenn jemand anderes helfen. Zum Betrachten von mehreren Spalten in einem Array müssen Sie sie mit einem Komma trennen (,) der Arbeitscode lautet:

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

Verwandte Themen