I am creating an editable table with php and AJAX, I have done everything but it does not print the data in the table, I do not know why, because it does not give me any errors, I do not know if I have something wrong in the code, I clarify that in the part of SCRIPT.js where I do the edit script is missing things, can you help me?:
INDEX.php
<div class="panel panel-primary">
<div class="panel-heading">Sample Data</div>
<div class="panel-body">
<div class="table-responsive">
<table id="personal" class="table table-bordered table-striped">
<thead>
<tr>
<th >Incidencia
</th>
<th >Departamento
</th>
<th >Usuario
</th>
<th >Estado
</th>
<th >Fecha de apertura
</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
</div>
</div>
DATA.php
<?php
include('dbconect.php');
$column = array("incidencia", "nom_dep", "usuario", "estado","fecha_inicio");
$query = "SELECT incidencia.*, usuarios.usuario, departamento.nom_dep,estado.estado FROM incidencia";
if(isset($_POST["search"]["value"]))
{
$query .= '
INNER JOIN usuarios ON usuarios.id = incidencia.usuario"%'.$_POST["search"]["value"].'%"
OR INNER JOIN departamento ON departamento.cod = incidencia.nom_dep LIKE "%'.$_POST["search"]["value"].'%"
OR INNER JOIN estado ON estado.id = incidencia.estado LIKE "%'.$_POST["search"]["value"].'%"
';
}
if(isset($_POST["order"]))
{
$query .= 'ORDER BY '.$column[$_POST['order']['0']['column']].' '.$_POST['order']['0']['dir'].' ';
}
else
{
$query .= 'ORDER BY incidencia asc ';
}
$query1 = '';
if($_POST["length"] != -1)
{
$query1 = 'LIMIT ' . $_POST['start'] . ', ' . $_POST['length'];
}
$statement = $conexion->prepare($query);
$statement->execute();
$number_filter_row = $statement->rowCount();
$statement = $conexion->prepare($query . $query1);
$statement->execute();
$result = $statement->fetchAll();
$data = array();
foreach($result as $row)
{
$sub_array = array();
$sub_array[] = $row['incidencia'];
$sub_array[] = $row['nom_dep'];
$sub_array[] = $row['usuario'];
$sub_array[] = $row['estado'];
$sub_array[] = $row['fecha_inicio'];
$data[] = $sub_array;
}
function count_all_data($conexion)
{
$query = "SELECT incidencia.*, usuarios.usuario, departamento.nom_dep,estado.estado FROM incidencia INNER JOIN usuarios ON usuarios.id = incidencia.usuario INNER JOIN departamento ON departamento.cod = incidencia.nom_dep INNER JOIN estado ON estado.id = incidencia.estado";
$statement = $conexion->prepare($query);
$statement->execute();
return $statement->rowCount();
}
$output = array(
'draw' => intval($_POST['draw']),
'recordsTotal' => count_all_data($conexion),
'recordsFiltered' => $number_filter_row,
'data' => $data
);
echo json_encode($output);
?>
SCRIPT.js
$(document).ready(function() {
var dataTable = $('#personal').DataTable({
"language": {
"url": "//cdn.datatables.net/plug-ins/1.10.20/i18n/Spanish.json"
},
"processing": true,
"serverSide": true,
"order": [],
"ajax": {
url: "datos.php",
type: "POST"
}
});
$('#personal').on('draw.dt', function() {
$('#personal').Tabledit({
url: 'edicion.php',
dataType: 'json',
columns: {
identifier: [0, 'incidencia'],
editable: [
[1, 'nom_dep'],
[2, 'usuario'],
[3, 'estado'],
[4, 'fecha_inicio']
]
},
restoreButton: false,
onSuccess: function(data, textStatus, jqXHR) {
if (data.action == 'delete') {
$('#' + data.idp).remove();
$('#personal').DataTable().ajax.reload();
}
}
});
});
});
you need to add the data