Modify table field by clicking on the Boolean field

0

I have a select query to show me the exams that a student has done in a table. There are two fields in that table that I modify dynamically with select in javascript but I have another boolean field that I would like to make when clicking change from 0 (you have not done the exam) to 1 (you have done the exam). The code that I have is the following:

<td><div class="select1" id="type-<?php echo $id_appl ?>"><?php echo $row['type']?></div></td>

<td> <?php echo $examen ?>
// este es el campo que me gustaria cambiar al hacer click de 0 a 1 o viceversa//                                                                                                                          </td>

$(document).ready(function() { 

// ambos procesaran en save.php 

// servira para editar los de tipo input text. 
$('.text').editable('colleges_save.php'); 

// servira para editar el cuadro combinado de paises 
$('.select1').editable('colleges_save.php', { 
data : " {'EAC':'EAC','ED1':'ED1','ED2':'ED2', 'REG':'REG', 'ROL':'ROL'}", 
type : 'select', 
submit : 'Ok' 
});

$('.select2').editable('colleges_save.php', { 
data : " {'Pending':'Pending','Accepted':'Accepted','Denied':'Denied', 'Waitlist':'Waitlist'}", 
type : 'select', 
submit : 'Ok' 
}); 

// servira para editar el textarea. 
$('.textarea').editable('colleges_save.php', { 
type : 'textarea', 
submit : 'Ok' 
}); 

});

COLLEGES_SAVE.PHP

$data = explode("-",$_POST['id']); 
$campo = $data[0]; // nombre del campo
$id = $data[1]; // id del registro 
$value = $_POST['value']; // valor por el cual reemplazar 


// sql para actualizar el registro 
$query = mysql_query("UPDATE applications SET ".$campo." = '".$value."' 
WHERE id_application = '".$id."'" ); 
echo ($campo == 'id_pais') ? $paises[$value] : $value; 
?>
    
asked by Vieira 22.03.2018 в 12:58
source

1 answer

2

In general, you should assign an event to the element that you want to update the record in the database. Once the event was clicked, send the ajax request to the page COLLEGES_SAVE.PHP with its respective parameters:

$("#registro-db").click(function(){
   var id = obtenerId();
   var data ={ 
     id : id,
     //aqui definirias los demas campos
   };

   $.post("/COLLEGES_SAVE.PHP", data, function(response){
          alert("estado actualizado");
   });

});
    
answered by 22.03.2018 / 13:18
source