2011-08-11 7 views
0

DataTablesプラグイン用のクライアントサイドフィルタリング(組み込み)は本当に素晴らしいです。それはあなたの検索ワードに基づいて、結果を任意のフィールドの単語ごとにフィルタリングします。JQuery Datatables用のサーバーサイドフィルタリング組み込みのクライアントサイドフィルタを模倣するプラグイン

提供されているServer Side Codeの例は、文字列全体を任意のフィールドで検索します。どのように私はこれを変更するでしょうか

$sWhere = ""; 
if ($_GET['sSearch'] != "") { 
    $sWhere = "WHERE ("; 
    for ($i = 0; $i < count($aColumns); $i++) { 
     $sWhere .= $aColumns[$i] . " LIKE '%" . mysql_real_escape_string($_GET['sSearch']) . "%' OR "; 
    } 
    $sWhere = substr_replace($sWhere, "", -3); 
    $sWhere .= ')'; 
} 

私が探しているものを達成するには?次の

これまでのところ、私が試したレンディション:まったく運と

$sWhere = ""; 
if ($_GET['sSearch'] != "") { 
    $sWhere = "WHERE ("; 
    $words = explode(" ",$_GET['sSearch']); 
    for ($i = 0; $i < count($aColumns); $i++) { 
     for($j = 0; $j < count($words); $j++) { 
      if($words[$j] != "") { 
       $sWhere .= $aColumns[$i] . " LIKE '%" . mysql_real_escape_string($words[$j]) . "%' OR "; 
      } 
     } 
    } 
    $sWhere = substr_replace($sWhere, "", -3); 
    $sWhere .= ')'; 
} 

。私は、検索文字列のすべての「単語」をループし、各列をそれらに対して検索する必要があると仮定します。今私は論理を失っている。私はすべての単語のすべてのフィールドを探しています、私はちょうど介してANDとOR私は、次の表に

|col1 | col2 | col3 
    ----------------------- 
#1| aaa | bbb | ccc 
#2| aaa | ddd | xxx 
#3| hugo | aaa | rap 

を持っていると私は、「AAA BBB」を検索する場合、私は結果だけ番号を返すような方法でそれらのグループに必要3つすべてではない。 私はこれが簡単だと知っています。しかし、私は自分自身を失ってしまったので、私はそれに私の頭脳をラッキングしてきました。

+0

回答しました。下記参照。ありがとう。 – rlemon

答えて

1

ここで私の新しいサーバーサイド検索は... DataTableで同じ機能を実装したい場合は誰でも可能です。

$sWhere = ""; 
if ($_GET['sSearch'] != "") { 
    $sWhere = "WHERE ("; 
    $words = explode(" ",$_GET['sSearch']); 
    for ($j = 0; $j < count($words); $j++) { 

     if ($words[$j] != "") { 
      $sWhere .= "("; 
      for ($i = 0; $i < count($aColumns); $i++) { 

       $sWhere .= $aColumns[$i] . " LIKE '%" . mysql_real_escape_string($words[$j]) . "%' OR "; 

      } 
      $sWhere = substr_replace($sWhere, "", -3); 
      $sWhere .= ") AND "; 
     } 
    } 
    $sWhere = substr_replace($sWhere, "", -4); 
    $sWhere .= ')'; 
} 
関連する問題