How to execute a query after loading table using Ajax

How to execute a query after loading table using Ajax

AdrianRNAdrianRN Posts: 1Questions: 1Answers: 0

Hi, I have a table that i'm filling using:

$(document).ready(function(){
         $('#tablaDatos').DataTable({
            "destroy": true,
            "ajax":{
                 "url": "consulta.php",
                 "dataSrc": "",
             },
             "columns":[
                 {"data": "id"},
                 {"data": "sensor1"},
                 {"data": "sensor2"},
                 {"data": "sensor3"},
             ]
         });
      });

And this is how I'm calling the data

include_once 'conexion.php';
$objeto = new Conexion();
$conexion = $objeto->Conectar();

$consulta = "SELECT * FROM datos";
$resultado = $conexion->prepare($consulta);
$resultado->execute();
$datos=$resultado->fetchAll(PDO::FETCH_ASSOC);

print json_encode($datos, JSON_UNESCAPED_UNICODE);
$conexion = null;

My question is How can I execute this query

$sensor1 = $_GET['sensor1'];
$sensor2 = $_GET['sensor2'];
$sensor3 = $_GET['sensor3'];

$query = ("INSERT INTO datos (sensor1, sensor2, sensor3) VALUES ('$sensor1', '$sensor2', '$sensor3')");

$exe = $conexion->exec($query);

thanks in advance

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    I might be missing something, but isn't that data already in the table, as you've just queried it to send it back to DataTables?

    Colin

Sign In or Register to comment.