Exécution requête sur bouton sur une ligne tableau
Posté : 04 juil. 2017, 15:27
Bonjour, j'ai un petit soucis de requete mysql je m'explique j'aimerais mettre a jour la colonne "statut" via un checkbox en cliquant sur un bouton mais lorsque je clique sur le bouton rien se passe.
je voudrais savoir si mon code est bon
requette.php
ajax
bouton
merci
cordialement
je voudrais savoir si mon code est bon
requette.php
Code : Tout sélectionner
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "smartphone";
$conn = mysqli_connect($servername, $username, $password, $dbname) or die("Connection failed: " . mysqli_connect_error());
$data_ids = $_REQUEST['data_ids'];
$data_id_array = explode(",", $data_ids);
if(!empty($data_id_array)) {
foreach($data_id_array as $Or_Affectation) {
$sql = "UPDATE abonnements SET Statut = 'Non Affecté' ";
$sql.=" WHERE Or_Affectation = '".$Or_Affectation."'";
$query=mysqli_query($conn, $sql) or die("supr_Affect.php: Suprimer Affectation");
}
}
?>Code : Tout sélectionner
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"></th></tr></tbody>');
$("#vu_affect_empl_processing").css("display","none");
}
}
} );
$("#action_ligne").on('click',function() { // bulk checked
var status = this.checked;
$(".updateRow").each( function() {
$(this).prop("checked",status);
});
});
$('#update_affect').on("click", function(event){ // triggering delete one by one
if( $('.updateRow:checked').length > 0 ){ // at-least one checkbox checked
var ids = [];
$('.updateRow').each(function(){
if($(this).is(':checked')) {
ids.push($(this).val());
}
});
var ids_string = ids.toString(); // array to string conversion
$.ajax({
type: "POST",
url: "supr_Affect.php",
data: {data_ids:ids_string},
success: function(result) {
dataTable.draw(); // redrawing datatable
},
async:false
});
}
});
} );Code : Tout sélectionner
<button class="Menu" id="update_affect">Suprimer Affectation</button>cordialement