jquery - How to pass a data retrieved from DataTable to PHP -


i have been able retrieve data first column of datatable, alert on jquery.

but now, need pass data php, use on query in order retrieve data database.

but not beeing able this...could 1 me?

    <?php       include 'db.php';      session_start();         if(array_key_exists("matricula",$_cookie))       {           $_session['matricula'] = $_cookie['matricula'];       }        if (array_key_exists("matricula",$_session))       {        }       else       {         echo "<script> window.location.replace('login.php') </script>";       }       ?> <!doctype html> <html>  <head>      <meta charset="utf-8">     <meta name="viewport" content="width=device-width, initial-scale=1.0">      <title>gestão cartões diária</title>      <link href="css/bootstrap.min.css" rel="stylesheet">     <link href="font-awesome/css/font-awesome.css" rel="stylesheet">      <link href="css/plugins/datatables/datatables.min.css" rel="stylesheet">      <link href="css/animate.css" rel="stylesheet">     <link href="css/style.css" rel="stylesheet">      <link href="//cdn.datatables.net/plug-ins/1.10.15/sorting/currency.js" rel="stylesheet">      <link href="https://cdn.datatables.net/select/1.2.2/css/select.datatables.min.css"  rel="stylesheet" type="text/css"/>  </head>  <body>      <div id="wrapper">           <?php              $query = "select `funcao` `tb_usuarios` `matricula`='".mysqli_real_escape_string($conn,$_session['matricula'])."'";             $result = mysqli_query($conn,$query);             $row = mysqli_fetch_array($result);             if( $row['funcao'] == 'empregado')             {                 include("layout_empregado.php");                             }             else             {                 include("layout_supervisor.php");                            }         ?>      </div>          <?php             if (isset($_post['ano_gasto']) , isset($_post['mes_gasto']))             {                 $sqlselect = "select * tb_gastos_alimentacao matricula '".mysqli_real_escape_string($conn,$_session['matricula'])."' , ano like'".$_post['ano_gasto']."' , mes '".$_post['mes_gasto']."'";              }             else             {                 $sqlselect = "select * tb_gastos_alimentacao matricula '".mysqli_real_escape_string($conn,$_session['matricula'])."'";               }         ?>          <div class="row wrapper border-bottom white-bg page-heading">             <div class="col-lg-10">                 <h2>consulta gastos usuário <?php echo $_session['matricula'] ?></h2>                 <ol class="breadcrumb">                     <li>                         <a href="#">home</a>                     </li>                     <li class="active">                         <strong>gastos cartão</strong>                     </li>                 </ol>             </div>         </div>          <div class="wrapper wrapper-content animated fadeinright">              <div class="row">                 <form method="post">                     <div class="col-lg-12">                         <div class="ibox float-e-margins">                             <div class="ibox-title">                                 <h5>dados usuário <?php echo ($_session['matricula']) ?></h5>                                 <div class="ibox-tools">                                     <a class="collapse-link">                                         <i class="fa fa-chevron-up"></i>                                     </a>                                 </div>                             </div>                             <div class="ibox-content">                                  <div class="row">                                 <div class="col-xs-2 form-group">                                     <label>matrícula</label>                                     <input class="form-control" type="text" disabled="disabled" value="<?php echo $dados_usuario['matricula']; ?>"/>                                 </div>                                 <div class="col-xs-7 form-group">                                     <label>portador cartão</label>                                     <input class="form-control" type="text" disabled="disabled" value="<?php echo $dados_usuario['nome']; ?>"/>                                 </div>                                 <div class="col-xs-3 form-group">                                     <label>nº cartão</label>                                     <input class="form-control" type="text" disabled="disabled" value="<?php echo $dados_usuario['cartao']; ?>"/>                                 </div>                                 </div>                                  <div class="row">                                 <div class="col-xs-2 form-group">                                     <label>centro de custos</label>                                     <input class="form-control" type="text" disabled="disabled" value="<?php echo $dados_usuario['centro_custo']; ?>"/>                                 </div>                                 <div class="col-xs-7 form-group">                                     <label>supervisão</label>                                     <input class="form-control" type="text" disabled="disabled" value="<?php echo $dados_usuario['supervisao']; ?>"/>                                 </div>                                 <div class="col-xs-3 form-group">                                     <label>lotação</label>                                     <input class="form-control" type="text" disabled="disabled" value="<?php echo $dados_usuario['lotacao']; ?>"/>                                 </div>                                 </div>                                  <div class="row">                                 <div class="col-xs-2 form-group">                                     <label>mês</label>                                     <select class="form-control m-b" id="cmbmesgasto" name="mes_gasto">                                         <option value="%">todos</option>                                         <option>janeiro</option>                                         <option>fevereiro</option>                                         <option>março</option>                                         <option>abril</option>                                         <option>maio</option>                                         <option>junho</option>                                         <option>julho</option>                                         <option>agosto</option>                                         <option>setembro</option>                                         <option>outubro</option>                                         <option>novembro</option>                                         <option>dezembro</option>                                     </select>                                     <input type="hidden" name="mes_selecionado" id="mes_selecionado" value="" />                                 </div>                                 <div class="col-xs-2 form-group">                                     <label>ano</label>                                     <select class="form-control m-b" id="cmbanogsto" name="ano_gasto">                                         <option value="%">todos</option>                                         <option>2015</option>                                         <option>2016</option>                                         <option>2017</option>                                         <option>2018</option>                                         <option>2019</option>                                         <option>2020</option>                                     </select>                                     <input type="hidden" name="ano_selecionado" id="ano_selecionado" value="" />                                 </div>                                 <div class="col-xs-2 form-group">                                     <button class="btn btn-primary" type="submit" name="pesquisa_data" id="pesquisa_data">buscar</button>                                     <button class="btn btn-primary" type="submit" name="teste" id="teste">teste</button>                                 </div>                                 </div>                             </div>                         </div>                     </div>                 </form>             </div>              <div class="row">                 <div class="col-lg-12">                     <div class="ibox float-e-margins">                         <div class="ibox-title">                             <h5>consulta aos gastos usuário <?php echo ($_session['matricula']) ?></h5>                             <div class="ibox-tools">                                 <a class="collapse-link">                                     <i class="fa fa-chevron-up"></i>                                 </a>                             </div>                         </div>                         <div class="ibox-content">                      <div class="table-responsive">                         <table class="table table-striped table-bordered table-hover datatables-example" id="tabela" >                         <thead>                             <tr>                                 <th>data lanc.</th>                                 <th>núm. trans.</th>                                 <th>estabelecimento</th>                                 <th>localidade</th>                                 <th>valor</th>                             </tr>                         </thead>                         <tbody>                          <?php                             $result_set =  mysqli_query($conn,$sqlselect);                             while($row = mysqli_fetch_array($result_set))                             {                         ?>                              <tr class="gradex">                                 <td><?php echo $row['data_lancamento']; ?></td>                                 <td><?php echo $row['num_transacao']; ?></td>                                 <td><?php echo $row['estabelecimento']; ?></td>                                 <td><?php echo $row['localidade']; ?></td>                                 <td><?php echo $row['valor']; ?></td>                             </tr>                              <?php                                 }                             ?>                          </tbody>                         <tfoot>                         <tr>                             <th>data lanc.</th>                             <th>núm. trans.</th>                             <th>estabelecimento</th>                             <th>localidade</th>                             <th>valor</th>                         </tr>                         </tfoot>                         </table>                     </div>                          </div>                     </div>                 </div>             </div>             <button id="btn">click</button>         </div>            <?php include("rodape.php"); ?>      <!-- scripts -->     <script src="js/jquery-2.1.1.js"></script>     <script src="js/bootstrap.min.js"></script>     <script src="js/plugins/metismenu/jquery.metismenu.js"></script>     <script src="js/plugins/slimscroll/jquery.slimscroll.min.js"></script>     <script src="js/plugins/jeditable/jquery.jeditable.js"></script>     <script src="js/plugins/datatables/datatables.min.js"></script>     <script src="//cdn.datatables.net/plug-ins/1.10.15/sorting/currency.js"></script>     <script src="https://cdn.datatables.net/select/1.2.2/js/datatables.select.min.js"></script>       <!-- custom , plugin javascript -->     <script src="js/inspinia.js"></script>     <script src="js/plugins/pace/pace.min.js"></script>      <!-- page-level scripts -->     <script>         $(document).ready(function(){             $('.datatables-example').datatable({                 dom: '<"html5buttons"b>ltfgitp',                 columndefs: [                     {                         targets: -1,                         data: 'valor',                         render: $.fn.datatable.render.number( '.', ',', 2, 'r$' )                     }                 ],                 buttons: [                     {extend: 'copy'},                     {extend: 'csv'},                     {extend: 'excel', title: 'examplefile'},                     {extend: 'pdf', title: 'examplefile'},                     {extend: 'print',                      customize: function (win){                         $(win.document.body).addclass('white-bg');                         $(win.document.body).css('font-size', '10px');                         $(win.document.body).find('table')                             .addclass('compact')                             .css('font-size', 'inherit');                         }                     }                 ]              });          });      //código para selecionar uma linha da tabela     $(document).ready(function() {         var table = $('#tabela').datatable();          $('#tabela tbody').on( 'click', 'tr', function () {             if ( $(this).hasclass('selected') ) {                 $(this).removeclass('selected');             }             else {                 table.$('tr.selected').removeclass('selected');                 $(this).addclass('selected');             }             var matricula_recuperada = table.cell('.selected', 0).data();             alert(matricula_recuperada);         } );     } );      </script>  </body>  </html> 

on last 20 lines, retrieve data datatable, , data wish pass php.

here picture of table...

complete tabe

thanks!

remove alert , use ajax like:

var matricula_recuperada = table.cell('.selected', 0).data();  $.ajax({   url: 'your url',   method: 'post',   data: {     id: matricula_recuperada   },   success: function(response)   {     // ever want here   } }); 

Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -