私のデータテーブルの行から正しいコンテンツを印刷する際に問題があります。DataTableが行から変更されたデータを取得します
私は、ファイルには、以下の内容でresponse.phpと呼ばれるがあります。
//include connection file
session_start();
include_once("connection.php");
// initilize all variable
$params = $columns = $totalRecords = $data = array();
$params = $_REQUEST;
//define index of column
$columns = array(
0 =>'log_in_timestamp',
1 =>'liDateInserted',
2 => 'browser',
3 => 'location',
4 => 'lo_li_time'
);
$where = $sqlTot = $sqlRec = "";
// check search value exist
if(!empty($params['search']['value'])) {
$where .=" WHERE ";
$where .=" (browser LIKE '".$params['search']['value']."%' ";
$where .=" OR location LIKE '".$params['search']['value']."%' ";
$where .=" AND ut.id = '".$_SESSION["userSession"]."%' ";
}
// getting total number records without any search
$sql = "SELECT li.log_in_timestamp, li.date_inserted liDateInserted, li.browser, li.location, (lo.log_out_timestamp - li.log_in_timestamp) lo_li_time, li.user_who_used_the_session, li.id historyId,
lo.id, lo.user_who_used_the_session, lo.log_out_timestamp, lo.date_inserted, ut.id, ut.username
FROM log_in_user_sessions li
LEFT JOIN log_out_user_sessions lo ON li.unique_id_login = lo.unique_id_logout
LEFT JOIN user_table ut ON li.user_who_used_the_session = ut.username
WHERE ut.id = '".$_SESSION["userSession"]."'";
$sqlTot .= $sql;
$sqlRec .= $sql;
//concatenate search sql if value exist
if(isset($where) && $where != '') {
$sqlTot .= $where;
$sqlRec .= $where;
}
$sqlRec .= " ORDER BY ". $columns[$params['order'][0]['column']]." ".$params['order'][0]['dir']." LIMIT ".$params['start']." ,".$params['length']." ";
$queryTot = mysqli_query($conn, $sqlTot) or die("database error:". mysqli_error($conn));
$totalRecords = mysqli_num_rows($queryTot);
$queryRecords = mysqli_query($conn, $sqlRec) or die("error to fetch employees data");
//iterate on results row and create new index array of data
while($row = mysqli_fetch_row($queryRecords)) {
$data[] = $row;
}
$json_data = array(
"draw" => intval($params['draw']),
"recordsTotal" => intval($totalRecords),
"recordsFiltered" => intval($totalRecords),
"data" => $data // total data array
);
echo json_encode($json_data); // send data as json format
は今私のindex.php に私はこのようなテーブルを呼び出す:
<div class="container">
<div class="">
<h3>User Sessions</h3><br>
<div class="">
<table id="employee_grid" class="display" width="100%" cellspacing="0">
<thead>
<tr>
<th>Time</th>
<th>Date</th>
<th>Browser</th>
<th>Location</th>
<th>Duration</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Time</th>
<th>Date</th>
<th>Browser</th>
<th>Location</th>
<th>Duration</th>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
私は次のようにjs
を試しました:
<script type="text/javascript">
$(document).ready(function() {
$('#employee_grid').DataTable({
"bProcessing": true,
"serverSide": true,
"columnDefs": [
{ "width": "20%", "defaultContent": "Not Logged Out","targets": "_all" }
],
"fnRowCallback": function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
// Bold the grade for all 'A' grade browsers
if (!aData[4])
{
$(nRow).addClass('alert-danger').css('background-color', '#f2dede');
}
},
"lengthMenu": [[5, 10, 25, 50, -1], [5, 10, 25, 50, "All"]],
"responsive": true,
"ajax":{
url :"../test/dt/dt_i/response.php",
type: "post",
error: function() {
$("#employee_grid_processing").css("display", "none");
}
}
});
});
</script>
私の出力は次のようになります。私はphp
に自分のために同じことを作成しました、それはこのようになります
。どのようにiが出力権利がunixtimestamp
などのデータを書式設定することができ、iはhere、hereまたはhere
:私は、DataTableには次のようになりたいです私の第二写真右CSSの背景と
編集:
は、私はに私のSQLステートメントを変更:
SELECT FROM_UNIXTIME(li.log_in_timestamp, '%H:%i'), DATE(li.date_inserted) liDateInserted, li.browser, li.location, FROM_UNIXTIME((lo.log_out_timestamp - li.log_in_timestamp), '%H:%i:%sh') lo_li_time, li.user_who_used_the_session, li.id historyId,
lo.id, lo.user_who_used_the_session, lo.log_out_timestamp, lo.date_inserted, ut.id, ut.username
FROM log_in_user_sessions li
LEFT JOIN log_out_user_sessions lo ON li.unique_id_login = lo.unique_id_logout
LEFT JOIN user_table ut ON li.user_who_used_the_session = ut.username
WHERE ut.id = '" . $_SESSION["userSession"] . "'
と今ではすべてが正しくフォーマットされていますが、CSS-背景にまだ問題がある...
は、誰かがここでこのラインを修正することはできますか?:
"fnRowCallback": function(column, aData, iDisplayIndex, iDisplayIndexFull) {
// Bold the grade for all 'A' grade browsers
if (!aData[4])
{
$(column).addClass('alert-danger').css('background-color', '#f2dede');
}
},
2番目の写真では、日付カラムの下の日付と日付カラムの下に日付を表示しています。なぜそうですか? –
ええ、私はそのbtwを変更する必要があります。それを更新情報 – Blueblazer172
@MayankPandeyzに感謝:) – Blueblazer172