我正在使用Datatables來創建我應該用來控制MySQL表的一個網頁(一個非常普通的任務)。有一件事我不知道爲什麼它不起作用。我想添加一個列到我的表contaninig複選框,所以稍後我可以使用這些javascript代碼在行上執行一些操作。 反正這裏是我的代碼:使用數據表添加複選框
的index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Process manager</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="css/bootstrap/navbar-static-top.css" rel="stylesheet">
<!-- DataTables bootstrap CSS -->
<link href="css/dataTables/dataTables.bootstrap.css" rel="stylesheet">
</head>
<body>
<table id="processManager" class="table table-striped table-bordered">
<thead>
<tr>
<th></th>
<th>process</th>
<th>Resource</th>
<th>Category</th>
<th>Format</th>
<th>Automaticity</th>
<th>Process_type</th>
<th>Access</th>
<th>Source</th>
<th>A</th>
<th>B</th>
<th>status_A</th>
<th>status_B</th>
<th>time_A</th>
<th>time_B</th>
<th>exec_A</th>
<th>exec_B</th>
<th>period</th>
<th>overtime</th>
<th>param</th>
<th>last_update</th>
<th>last_triples</th>
<th>error</th>
<th>description</th>
</tr>
</thead>
<tfoot>
<tr>
<th></th>
<th>process</th>
<th>Resource</th>
<th>Category</th>
<th>Format</th>
<th>Automaticity</th>
<th>Process_type</th>
<th>Access</th>
<th>Source</th>
<th>A</th>
<th>B</th>
<th>status_A</th>
<th>status_B</th>
<th>time_A</th>
<th>time_B</th>
<th>exec_A</th>
<th>exec_B</th>
<th>period</th>
<th>overtime</th>
<th>param</th>
<th>last_update</th>
<th>last_triples</th>
<th>error</th>
<th>description</th>
</tr>
</tfoot>
</table>
<script src="js/jquery/jquery-1.11.1.min.js"></script>
<script src="js/bootstrap/bootstrap.min.js"></script>
<script src="js/dataTables/jquery-1.10.1.dataTables.min.js"></script>
<script src="js/dataTables/dataTables.bootstrap.js"></script>
<script>
$(document).ready(function loadData() {
processManager = $('#processManager').DataTable({
"ajax": {
url: "getSingleTable.php",
},
"columns": [
{
"orderable": false,
// Create an HTML select with all the versions of the data
//TODO Correggi +01
"data": function (row, type, val, meta) {
return '<input type="checkbox"/>';
}
},
{ "data": "Process ID" },
{ "data": "Resource" },
{ "data": "Category" },
{ "data": "Format" },
{ "data": "Automaticity" },
{ "data": "Process type" },
{ "data": "Access" },
{ "data": "Source" },
{ "data": "A" },
{ "data": "B" },
{ "data": "Status A" },
{ "data": "Status B" },
{ "data": "Time A" },
{ "data": "Time B" },
{ "data": "Exec A" },
{ "data": "Exec B" },
{ "data": "Period" },
{ "data": "Overtime" },
{ "data": "Parameters" },
{ "data": "Last Update" },
{ "data": "Last Triples" },
{ "data": "Error" },
{ "data": "Description" }
],
"language": {
"decimal": ",",
"thousands": "."
},
"lengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
"order": [[0, 'asc']],
"pagingType": "full_numbers",
"processing": true,
"serverSide": true,
"stateSave": true
});
});
</script>
</body>
</html>
getSingleTable.php
<?php
// DB table to use
// $table = 'process_manager';
$table = 'process_manager2';
// Table's primary key
// $primaryKey = 'Process';
$primaryKey = 'Process';
// Array of database columns which should be read and sent back to DataTables.
// The `db` parameter represents the column name in the database, while the `dt`
// parameter represents the DataTables column identifier. In this case simple
// indexes
$columns = array (
array (
'db' => 'process',
'dt' => 'Process ID'
),
array (
'db' => 'Resource',
'dt' => 'Resource'
),
array (
'db' => 'Category',
'dt' => 'Category'
),
array (
'db' => 'Format',
'dt' => 'Format'
),
array (
'db' => 'Automaticity',
'dt' => 'Automaticity'
),
array (
'db' => 'Process_type',
'dt' => 'Process type'
),
array (
'db' => 'Access',
'dt' => 'Access'
),
array (
'db' => 'Source',
'dt' => 'Source'
),
array (
'db' => 'A',
'dt' => 'A'
),
array (
'db' => 'B',
'dt' => 'B'
),
array (
'db' => 'status_A',
'dt' => 'Status A'
),
array (
'db' => 'status_B',
'dt' => 'Status B'
),
array (
'db' => 'time_A',
'dt' => 'Time A'
),
array (
'db' => 'time_B',
'dt' => 'Time B'
),
array (
'db' => 'exec_A',
'dt' => 'Exec A'
),
array (
'db' => 'exec_B',
'dt' => 'Exec B'
),
array (
'db' => 'period',
'dt' => 'Period'
),
array (
'db' => 'overtime',
'dt' => 'Overtime'
),
array (
'db' => 'param',
'dt' => 'Parameters'
),
array (
'db' => 'last_update',
'dt' => 'Last Update'
),
array (
'db' => 'last_triples',
'dt' => 'Last Triples'
),
array (
'db' => 'error',
'dt' => 'Error'
),
array (
'db' => 'description',
'dt' => 'Description'
)
);
// SQL server connection information
$sql_details = array (
'user' => 'USER',
'pass' => 'PASS',
'db' => 'DB',
'host' => 'IP'
);
require ('ssp.class.php');
echo json_encode (SSP::simple ($_GET, $sql_details, $table, $primaryKey, $columns));
而是 「USER」, 「PASS」, 「DB」 和 「IP」 的我把真正的價值當然。 一切工作正常,如果我不試圖把複選框。 正如你可以看到我試圖把複選框放在第一列,在「進程」之前,這應該是唯一不存在於MySQL表中的列。 任何人都知道什麼是錯的?
現在,讓我這個錯誤:數據表警告:表ID = ProcessManager的 - 發生SQL錯誤:SQLSTATE [42000]:語法錯誤或訪問衝突: 1064你的SQL語法有錯誤;檢查對應於你的MySQL服務器版本的手冊,在第5行的'LIMIT 0,10'附近使用正確的語法。 – giogix 2014-09-29 07:20:45
嗯,這是一個SQL問題。它與JS無關。你有SQL代碼還是以某種方式生成的? – Dmitry 2014-09-29 07:38:04
我把代碼放在答案中。 – giogix 2014-09-29 07:43:50