DataTableプラグインを使用して、動的な方法でmySQLデータベーステーブルを表示しています。この表では、「checkinDateTime」列にdatetime形式が使用されています。私のテーブルでは、日付/時刻は2016-04-15 14:27:36
です。私はここに私のコードである可能性がApril 15, 2016, 2:27 pm
テーブル内のDataTable書式設定日時列
のようにフォーマットされた、これは読みやすくしたいと思います:。
Reports.php(ユーザがテーブルを見ることができる場所ですが、私はDataTableのスクリプトを表示するつもりですそして、その設定):
<script>
$(document).ready(function() {
$('#checkin').DataTable({
"bProcessing": true,
"serverSide": false,
"dom": 'lBfrtip',
"buttons": [
{
extend: 'collection',
text: 'Export',
buttons: [
'copy',
'excel',
'csv',
'pdf',
'print'
]
}
],
"ajax":{
url :"response.php", // json datasource
type: "post", // type of method ,GET/POST/DELETE
data: {}
}
});
});
</script>
Response.php(DataTableのデータを引き込む方法):
<?php
//include connection file
include_once("../connection.php");
// initilize all variable
$params = $columns = $totalRecords = $data = array();
$params = $_REQUEST;
//define index of column
$columns = array(
0 => 'id',
1 => 'suid',
2 => 'staffMember',
3 => 'studentName',
4 => 'studentEmail',
5 => 'checkinDateTime'
);
$where = $sqlTot = $sqlRec = "";
// check search value exist
if(!empty($params['search']['value'])) {
$where .=" WHERE ";
$where .=" (studentName LIKE '".$params['search']['value']."%' ";
$where .=" OR staffMember LIKE '".$params['search']['value']."%' ";
$where .=" OR studentEmail LIKE '".$params['search']['value']."%' ";
$where .=" OR suid LIKE '".$params['search']['value']."%' ";
$where .=" OR checkinDate LIKE '".$params['search']['value']."%')";
}
// getting total number records without any search
$sql = "SELECT * FROM `checkin` ";
$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($VisitorManagement, $sqlTot) or die("database error:". mysqli_error($VisitorManagement));
$totalRecords = mysqli_num_rows($queryTot);
$queryRecords = mysqli_query($VisitorManagement, $sqlRec) or die("error to fetch check-in 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
?>
Connection.php(データベースへのアクセス):
l3210私はサポートフォーラムを見てきましたが、ここでも同様ですが、自分のコードで動作する解決策が見つかりませんでした。
経由でそれを行いますプロブラムは何ですか?たぶんそれは最も近いとされたあなたの試行を示すのに役立つでしょう。私は、PHPを介して、SQLを介してJavaスクリプトを介して日付のローカリゼーションをやって覚えている、そこには、1つは、それをやりたいかもしれないかなりの層があります。しかし、最終的に誰かが "データテーブル"などを知っている誰かがすでに最高の解決策を知っています... – Dilettant