Database column value in a hidden HTML field

0

I want to get the value of the column and store it in a variable.

This code works fine, but I now need to fill in the value of the hidden field with the ID that comes from the database:

"columns": [
   { "data": "cpf" },
   { "data": "nome" , },
   { "data": "sobrenome" , },
   { "data": "celular" },
   { "data": "email" },
   {               
   "data": null,
   "defaultContent": "<form method=\"post\" action=\"\"><input type=\"hidden\" id=\"idcontrib\" name=\"idcontrib\" value=\"  => "DATA": "ID" <=    \"><button type=\"submit\" class=\"btn btn-warning btn-xs\" name=\"edit_contrib\">Editar</button>&nbsp;&nbsp;<button type=\"submit\" class=\"btn btn-danger btn-xs\" name=\"exc_contrib\">Excluir</button></form>"
},

I have to make this part of the code:

value=\"  => "DATA": "ID" <=    \"

Be something like:

value=\"<?=$id?>\"

For this I have to make the value that comes from the database to be stored in the variable:

$id = "data" : "id";

Is it possible to do something like this?

HTML

<table id="datatable_fixed_column" class="table table-striped table-bordered" width="100%">
<thead>
  <tr>                                            
    <th>CPF</th>
    <th>Nome</th>
    <th>Sobrenome</th>
    <th>Celular</th>
    <th>email</th>
    <th>Ação</th>
  </tr>
</thead>                                    
</table>

javascript

<script type="text/javascript">

$(document).ready(function() {

    var otable = $('#datatable_fixed_column').DataTable({

    "processing": true,
    "serverSide": true,
    "ajax": "server_processing/contribuintes.php",

    "order": [[ 1, "asc" ]],


    "columns": [

        { "data": "cpf" },
        { "data": "nome" , },
        { "data": "sobrenome" , },
        { "data": "celular" },
        { "data": "email" },
        {                
        "data": null,

        "defaultContent": "<form method=\"post\" action=\"\"><input type=\"hidden\" id=\"idcontrib\" name=\"idcontrib\" value=\"<id>\"><button type=\"submit\" class=\"btn btn-warning btn-xs\" name=\"edit_contrib\">Editar</button>&nbsp;&nbsp;<button type=\"submit\" class=\"btn btn-danger btn-xs\" name=\"exc_contrib\">Excluir</button></form>"
        },

    ],


    "columnDefs": [

        { "width": "10%", "targets": 0 },
        { "width": "15%", "targets": 1 },
        { "width": "25%", "targets": 2 },
        { "width": "10%", "targets": 3 },
        { "width": "25%", "targets": 4 },
        { "width": "15%", "targets": 5 },


    ],

    "sDom": "<'dt-toolbar'<'col-xs-6'f><'col-xs-6'<'toolbar'>>r>"+
            "t"+
            "<'dt-toolbar-footer'<'col-xs-6'i><'col-xs-6'p>>"
    });

     $("div.toolbar").html('<div class="text-right"><form method="post" action=""><button type="submit" class="btn btn-success" name="add">ADICIONAR NOVO CONTRIBUINTE</button></form></div>');

})

Server-side script

$table = 'tbl_contribuintes';
$primaryKey = 'id_contrib';

$columns = array(

  array( 'db' => 'cpf', 'dt' => 'cpf' ),
  array( 'db' => 'fnome',  'dt' => 'nome' ),
  array( 'db' => 'lnome',  'dt' => 'sobrenome' ),   
  array( 'db' => 'celular1',  'dt' => 'celular' ),
  array( 'db' => 'email',  'dt' => 'email' ),
  array( 'db' => 'id_contrib', 'dt' => 'id' )

);

$sql_details = array(
  'user' => 'root',
  'pass' => 'XXXXX',
  'db'   => 'XXXXX',
  'host' => 'localhost'
);

require( 'ssp.class.php' );

echo json_encode(
  SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);

Remembering that the data is being listed perfectly, just missing this detail is to get the value of the column and put it in the variable.

Thank you very much.

    
asked by anonymous 05.11.2014 / 13:18

1 answer

1

For someone who has the same question, the answer is:

SERVER-SIDE

$table = 'tbl_contribuintes';
$primaryKey = 'id_contrib';

$columns = array(

    array( 'db' => 'id_contrib', 'dt' => 0 ),
    array( 'db' => 'cpf', 'dt' => 1 ),
    array( 'db' => 'fnome',  'dt' => 2 ),
    array( 'db' => 'lnome',  'dt' => 3 ),   
    array( 'db' => 'celular1',  'dt' => 4 ),
    array( 'db' => 'email',  'dt' => 5 ),
    array( 'db' => 'id_status',  'dt' => 6 ),

);

$sql_details = array(
  'user' => 'root',
  'pass' => 'XXX',
  'db'   => 'XXX',
  'host' => 'localhost'
);

require( 'ssp.class.php' );

echo json_encode(
  SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);

TABLE

<table id="datatable_fixed_column" class="table table-striped table-bordered" width="100%">
      <thead>
        <tr>
          <th>ID</th>
          <th>CPF</th>
          <th>Nome</th>
          <th>Sobrenome</th>
          <th>Celular</th>
          <th>email</th>
          <th>status</th>
          <th>Ação</th>                                                                                     
       </tr>
    </thead>                                            
</table>

SCRIPT

$(document).ready(function() {

    var otable = $('#datatable_fixed_column').DataTable({

    "processing": true,
    "serverSide": true,
    "ajax": "server_processing/contribuintes.php",

    "order": [[ 2, "asc" ]],

    "columnDefs": [

        { "width": "5%", "targets": 0 },
        { "width": "10%", "targets": 1 },
        { "width": "15%", "targets": 2 },
        { "width": "20%", "targets": 3 },
        { "width": "10%", "targets": 4 },
        { "width": "20%", "targets": 5 },
        { "width": "5%", "targets": 6 },
        { "render": actionlinks,
          "data": null,         
          "targets": [7], "width": "15%", "targets": 7 },

    ],

    });

    function actionlinks(data, type, full) {

        return '<form method="post" action=""><input type="hidden" id="idcontrib" name="idcontrib" value="' + full[0] + '"><button type="submit" class="btn btn-warning btn-xs" name="edit_contrib">Editar</button>&nbsp;&nbsp;<button type="submit" class="btn btn-danger btn-xs" name="exc_contrib">Excluir</button>&nbsp;&nbsp;<button type="submit" class="btn btn-info btn-xs" name="ativa_contrib">Reativar</button></form> ';

    }

Acknowledgments: Anderson Torres

    
07.11.2014 / 20:51