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> <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> <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.