Import problem database in table
Import problem database in table
I have a problem with my code, I can not get it like receiving basic data to give for my table
Here is the json code
`<?php
/* Database connection start */
$servername = "localhost";
$username = "root";
$password = "Mm101010";
$dbname = "smartphone";
$conn = mysqli_connect($servername, $username, $password, $dbname) or die("Connection failed: " . mysqli_connect_error());
/* Database connection end */
// storing request (ie, get/post) global array to a variable
$requestData= $_REQUEST;
$columns = array(
// datatable column index => database column name
0 => 'Or_Affectation',
1 => 'USER_ID',
2 => 'Nom',
3 => 'Prenom',
4 => 'Num_SIM',
5 => 'PIN_Terminal',
6 => 'PIN_SIM',
7 => 'Num_IMEI',
8 => 'Date_Debut',
9 => 'Date_Fin',
10 => 'Vitre',
11 => 'Coque',
12 => 'Support_Vehicule',
13 => 'Actif',
14 => 'Statut'
);
// getting total number records without any search
$sql = "SELECT Or_Affectation ";
$sql.=" FROM vu_affect_empl";
$query=mysqli_query($conn, $sql) or die("Affectation.php: get employees");
$totalData = mysqli_num_rows($query);
$totalFiltered = $totalData; // when there is no search parameter then total number rows = total number filtered rows.
$sql = "SELECT Or_Affectation, USER_ID, Nom, Prenom, Num_SIM, PIN_Terminal, PIN_SIM, Num_IMEI, Date_Debut, Date_Fin, Vitre, Coque, Support_Vehicule, Actif, Statut ";
$sql.=" FROM vu_affect_empl WHERE 1=1";
if( !empty($requestData['search']['value']) ) { // if there is a search parameter, $requestData['search']['value'] contains search parameter
$sql.=" AND ( USER_ID LIKE '".$requestData['search']['value']."%' ";
$sql.=" OR Num_SIM LIKE '".$requestData['search']['value']."%' ";
$sql.=" OR Nom LIKE '".$requestData['search']['value']."%' )";
}
$query=mysqli_query($conn, $sql) or die("Affectation.php: get employees");
$totalFiltered = mysqli_num_rows($query); // when there is a search parameter then we have to modify total number filtered rows as per search result.
$sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]." ".$requestData['order'][0]['dir']." LIMIT ".$requestData['start']." ,".$requestData['length']." ";
/* $requestData['order'][0]['column'] contains colmun index, $requestData['order'][0]['dir'] contains order such as asc/desc */
$query=mysqli_query($conn, $sql) or die("Affectation.php: get employees");
$data = array();
$i=1+$requestData['start'];
while( $row=mysqli_fetch_array($query) ) { // preparing an array
$nestedData=array();
$nestedData[] = "<input type='checkbox' class='deleteRow' value='".$row['Or_Affectation']."' /> #".$i ;
$nestedData[] = $row["USER_ID"];
$nestedData[] = $row["Nom"];
$nestedData[] = $row["Prenom"];
$nestedData[] = $row["Num_SIM"];
$nestedData[] = $row["PIN_Terminal"];
$nestedData[] = $row["PIN_SIM"];
$nestedData[] = $row["Num_IMEI"];
$nestedData[] = $row["Date_Debut"];
$nestedData[] = $row["Date_Fin"];
$nestedData[] = $row["Vitre"];
$nestedData[] = $row["Coque"];
$nestedData[] = $row["Support_Vehicule"];
$nestedData[] = $row["Actif"];
$nestedData[] = $row["Statut"];
$data[] = $nestedData;
$i++;
}
$json_data = array(
"draw" => intval( $requestData['draw'] ), // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw.
"recordsTotal" => intval( $totalData ), // total number of records
"recordsFiltered" => intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData
"data" => $data // total data array
);
echo json_encode($json_data); // send data as json format
<?php > ` ?>Here is the index code
`<!DOCTYPE html>
<html>
<title>Datatable Bulk Delete Server Side | CoderExample</title>
<head>
<link rel="stylesheet" type="text/css" href="css/jquery.dataTables.css">
<script type="text/javascript" language="javascript" src="js/jquery.js"></script>
<script type="text/javascript" language="javascript" src="js/jquery.dataTables.js"></script>
<script type="text/javascript" language="javascript" >
$(document).ready(function() {
var dataTable = $('#vu_affect_empl').DataTable( {
"processing": true,
"serverSide": true,
"columnDefs": [ {
"targets": 0,
"orderable": false,
"searchable": false
} ],
"ajax":{
url :"Affectation.php", // json datasource
type: "post", // method , by default get
error: function(){ // error handling
$(".vu_affect_empl-error").html("");
$("#vu_affect_empl").append('<tbody class="vu_affect_empl-error"><tr><th colspan="3">No data found in the server</th></tr></tbody>');
$("#vu_affect_empl_processing").css("display","none");
}
}
} );
$("#bulkDelete").on('click',function() { // bulk checked
var status = this.checked;
$(".deleteRow").each( function() {
$(this).prop("checked",status);
});
});
$('#deleteTriger').on("click", function(event){ // triggering delete one by one
if( $('.deleteRow:checked').length > 0 ){ // at-least one checkbox checked
var ids = [];
$('.deleteRow').each(function(){
if($(this).is(':checked')) {
ids.push($(this).val());
}
});
var ids_string = ids.toString(); // array to string conversion
$.ajax({
type: "POST",
url: "employee-delete.php",
data: {data_ids:ids_string},
success: function(result) {
dataTable.draw(); // redrawing datatable
},
async:false
});
}
});
} );
</script>
<style>
div.container {
margin: 0 auto;
max-width:760px;
}
div.header {
margin: 100px auto;
line-height:30px;
max-width:760px;
}
body {
background: #f7f7f7;
color: #333;
font: 90%/1.45em "Helvetica Neue",HelveticaNeue,Verdana,Arial,Helvetica,sans-serif;
}
</style>
</head>
<body>
<div class="header"><h1>DataTable Bulk Delete Server Side </h1></div>
<div class="container">
<table id="vu_affect_empl" cellpadding="0" cellspacing="0" border="0" class="display" width="100%">
<thead>
<tr>
<th><input type="checkbox" id="bulkDelete" /> <button id="deleteTriger">Delete</button></th>
<th>Or Affectation</th>
<td> </td>
<th>USER ID</th>
<th>Nom</th>
<th>Prenom</th>
<th>Num SIM</th>
<th>PIN Terminal</th>
<th>PIN SIM</th>
<th>Num EMEI</th>
<th>Date Debut</th>
<th>Date Fin</th>
<th>Vitre</th>
<th>Coque</th>
<th>Support Vehicule</th>
<th>Actif</th>
<th>Statut</th>
</tr>
</thead>
</table>
</div>
</body>
</html>
`
thx
Answers
So what happens? Are errors being reported?
When I open the page it shows me nothing while I would like it to display directly to me the data of my database on my table (see image 1) and when I made a search after two letter It shows me this error (see image 2) then when I click on ok, it shows me the results (see image 3)
Why this word is displayed and how it is that I am obliged to write on the bar to display the data
thx