[英]how to display datas from a single column from mysql php to multiple columns in datatables
我使用帶有 php mysql 和 ajax 的數據表來恢復三列中的數據,但是如何讓它們按圖像順序排列而不是重復,但我希望它們按以下順序按名稱排序,而不是重復。 在數據庫中,我只有一列“noms”用於從單列中檢索數據。 怎么做?
這是html
<thead>
<tr>
<th>id</th>
<th>Name1</th>
<th>Name2</th>
<th>Name3</th>
</tr>
</thead>
this is script
<script>
$(document).ready(function(){
$('#users').DataTable({
"processing": true,
"serverSide": true,
"ajax": "fetch.php"
})
});
</script>
這是 fetch.php
$columns = array(
array( 'db' => 'id', 'dt' => 0 ),
array( 'db' => 'noms', 'dt' => 1 ),
array( 'db' => 'noms', 'dt' => 2 ),
array( 'db' => 'noms', 'dt' => 3 )
);
$sql_details = array(
'user' => 'root',
'pass' => '',
'db' => '',
'host' => 'localhost'
);
require( 'ssp.class.php' );
echo json_encode(
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);
您可以通過 array_chunk() 函數將結果數組分解為多個數組:
Input : $input_array = array('a', 'b', 'c', 'd', 'e');
array_chunk($input_array, 2);
Output : Array(
[0] => Array
(
[0] => a
[1] => b
)
[1] => Array
(
[0] => c
[1] => d
)
[2] => Array
(
[0] => e
)
)
Input : $input_array = array('a', 'b', 'c', 'd', 'e');
array_chunk($input_array, 2, true)
Output : Array
(
[0] => Array
(
[0] => a
[1] => b
)
[1] => Array
(
[2] => c
[3] => d
)
[2] => Array
(
[4] => e
)
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.