2
このコードフィルタでは、検索とページ機能が機能していませんでしたが、動作しませんでしたので、コードをチェックしてください。私はコンセプトデータテーブルフィルタ、検索機能していませんmongodb php
<?php
mb_internal_encoding('UTF-8');
$database = 'test';
$collection = 'user';
/**
* MongoDB connection
*/
try{
// Connecting to server
$m = new MongoClient();
}catch(MongoConnectionException $connectionException){
print $connectionException;
exit;
}
$m_collection = $m->$database->$collection;
$input = $fields = $totalRecords = $data = array();
$input = & $_REQUEST;
$fields = array('id', 'name', 'email', 'gender,');
// Input method (use $_GET, $_POST or $_REQUEST)
/**
* Handle requested DataProps
*/
// Number of columns being displayed (useful for getting individual column search info)
$iColumns = & $input['iColumns'];
// Get mDataProp values assigned for each table column
$dataProps = array();
for ($i = 0; $i < $iColumns; $i++) {
$var = 'mDataProp_'.$i;
if (!empty($input[$var]) && $input[$var] != 'null') {
$dataProps[$i] = $input[$var];
}
}
$searchTermsAny = array();
$searchTermsAll = array();
if (!empty($input['sSearch'])) {
$sSearch = $input['sSearch'];
for ($i=0 ; $i < $iColumns ; $i++) {
if ($input['bSearchable_'.$i] == 'true') {
if ($input['bRegex'] == 'true') {
$sRegex = str_replace('/', '\/', $sSearch);
} else {
$sRegex = preg_quote($sSearch, '/');
}
$searchTermsAny[] = array(
$dataProps[$i] => new MongoRegex('/'.$sRegex.'/i')
);
}
}
}
// Individual column filtering
for ($i=0 ; $i < $iColumns ; $i++) {
if ($input['bSearchable_'.$i] == 'true' && $input['sSearch_'.$i] != '') {
if ($input['bRegex_'.$i] == 'true') {
$sRegex = str_replace('/', '\/', $input['sSearch_'.$i]);
} else {
$sRegex = preg_quote($input['sSearch_'.$i], '/');
}
$searchTermsAll[ $dataProps[$i] ] = new MongoRegex('/'.$sRegex.'/i');
}
}
$searchTerms = $searchTermsAll;
if (!empty($searchTermsAny)) {
$searchTerms['$or'] = $searchTermsAny;
}
$totalRecords =$m_collection->count();
$cursor = $m_collection->find($searchTerms, $fields);
/**
* Paging
*/
if (isset($input['iDisplayStart']) && $input['iDisplayLength'] != '-1') {
$cursor->limit($input['iDisplayLength'])->skip($input['iDisplayStart']);
}
/**
* Ordering
*/
if (isset($input['iSortCol_0'])) {
$sort_fields = array();
for ($i=0 ; $i<intval($input['iSortingCols']) ; $i++) {
if ($input[ 'bSortable_'.intval($input['iSortCol_'.$i]) ] == 'true') {
$field = $dataProps[ intval($input['iSortCol_'.$i]) ];
$order = ($input['sSortDir_'.$i]=='desc' ? -1 : 1);
$sort_fields[$field] = $order;
}
}
$cursor->sort($sort_fields);
}
foreach ($cursor as $doc)
{ $name = '<a href="profile.php?secure='.$doc['_id'].' " style = "color:red;">'.$doc['name'].'</a>';
$data[] = array($name, $doc['email'], $doc['gender]);
}
/**
* Output
*/
$json_data = array(
"draw"=> intval($input['draw']),
"recordsTotal" =>intval ($totalRecords),
"recordsFiltered" => intval($totalRecords),
"data" => $data
);
echo json_encode($json_data);
を追求するためにも、このコードファイルやドキュメントに関連する、それが参考になる
And also i need to Join two tables as given below.
表1
表2
感謝適切にそこに12 docのコレクションが、datatable(** 1から1のエントリ**を表示する)と私は25を設定することができます12docを表示することができますこのように表示することができます...私はエントリを表示し、次に得ることができますボタン.. –
これらの2行 '$ resultSet = $コレクション - > find(); $ iTotal = count($ resultSet); 'ページングを完全に維持するためのものです。 –
これはうまくいきます。#mayank、$ resultSet = $ collection-> find(); $ iTotal = $ resultSet-> count();うまく動作します –