In this second opportunity I consulted a problem that I have when wanting to show specific data of a foreign chart for an ID.
Waving more in detail, my web application is a database of entry of detainees (in Table 1 register the personal and judicial data) which within the penitentiary can cause situations of disturbance of order (in Table 2 record the riots). These tables are related to me and what I can not solve is how I can show the records of disturbances of a specific person stopped by a button that opens a modal with a table in which these alterations of the order would be shown (I use jquery's dataTables). The relationship would be ONE to MANY.
(- I notice that there are parts of the code that when I go up to this page, it does not take me in. I do not know why, I'm sorry, anyway I think they would not be the main problem -)
full code: link
Since thank you very much to those who take the trouble and I hope to have been as clear as possible.
index.php
IMG1.En index.php charge the dataTables with the records of the detained persons (Table 1)
IMG2.With that button I call a modal with dataTables that should show the records of disturbances of detainees (Table 2)
IMG3.Aca there is the modal, which shows the name of the person arrested but not the records of disturbances
index.php - >
<div class="row">
<div class="col-md-8"><input type="text" name="" class="form-control input-sm" id="title"
style="background: none;
border: none;
font-size: large;
font-weight: bold;
box-shadow: none;" disabled></div>
<div class="col-md-4"><button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span></button></div>
</div>
</div>
<div class="modal-body">
<div class="form-group"> <!-- TABLA Y CAMPOS -->
<div class="row">
<div class="col-md-6">
<label>Fecha/Hora</label><!--FECHA/HORA-->
<input type="datetime-local" name="" class="form-control input-sm" id="fechaalt">
</div>
<div class="col-md-6">
<label>Motivo</label> <!--MOTIVO-->
<select name="" class="form-control input-sm pull-right" id="motivoalt">
<option></option>
<option>DESCOMPENSACION</option>
<option>PELEA</option>
<option>INTENTO SUICIDIO</option>
<option>AUTOLESION</option>
<option>OTRO</option>
</select><br>
</div>
<div class="col-md-12">
<label>Descripcion</label> <!--LESION-->
<input type="text" name="" class="form-control input-sm" id="lesionalt" placeholder="Describir lesion"
style="font-size:25px;">
</div><br>
<div class="col-md-12">
<label></label> <!--BOTON-->
<button type="button" class="btn btn-primary" id="guardarnuevoAlt"
style="float: right; margin-top: 10px;">
Agregar
</button>
</div>
</div>
</div>
<hr>
<div id="tabla-alteracion"></div>
</div>
</div>
</div>
table.php (script dataTables jQuery) - >
<script type="text/javascript"> // <!-- SCRIPT - PARAS EL LISTADO DATABASE JQUERY -->
$(document).ready(function() {
$(".table").DataTable({
responsive: true,
"order": [], // --> Se desactiva el modo ordenar
"language": {
"lengthMenu": "Mostrar _MENU_ registros por página",
"search": "Buscar",
"info": "Mostrando <b>_START_</b> a <b>_END_</b> de <b>_TOTAL_</b> internos registrados",
"infoEmpty": "Mostrando 0 a 0 de 0 entradas",
"paginate": {
"first": "Primero",
"last": "Ultimo",
"next": "Siguiente",
"previous": "Anterior"
}
},
"rowCallback": function(row, data, index){
if(data[5].toUpperCase() == 'EGRESADO'){
$(row).find('td:eq(0)').css('background-color', '#F5B2B3'),
$(row).find('td:eq(1)').css('background-color', '#F5B2B3'),
$(row).find('td:eq(2)').css('background-color', '#F5B2B3'),
$(row).find('td:eq(3)').css('background-color', '#F5B2B3'),
$(row).find('td:eq(4)').css('background-color', '#F5B2B3'),
$(row).find('td:eq(5)').css('background-color', '#F5B2B3');
}
},
"columnDefs": [
{ className: "herr", "targets": [ 6 ] }
]
});
});
</script>
tabla.php (previous connection requirement) - >
<div class="row">
<div class="col-sm-12">
<table class="table table-hover table-condensed table-bordered">
<thead>
<tr style="text-align: center;">
<td style="font-weight: bold; font-size: large;">Fecha(Ingreso)</td>
<td style="font-weight: bold; font-size: large;">Apellido</td>
<td style="font-weight: bold; font-size: large;">Nombre</td>
<td style="font-weight: bold; font-size: large;">LPU</td>
<td style="font-weight: bold; font-size: large;">Origen</td>
<td style="font-weight: bold; font-size: large;">Aloj/Egr</td>
<td style="font-weight: bold; font-size: large;"></td>
</tr>
</thead>
<?php
$sql="SELECT * from ingresos ORDER BY id_ingresos DESC";
$result=mysqli_query($conexion,$sql);
while($ver=mysqli_fetch_row($result)){
$datos=$ver[0]."||".
$ver[1]."||".
$ver[2]."||".
$ver[3]."||".
$ver[4]."||".
$ver[5]."||".
$ver[6]."||".
$ver[7]."||".
$ver[8]."||".
$ver[9]."||".
$ver[10]."||".
$ver[11]."||".
$ver[12]."||".
$ver[13]."||".
$ver[14]."||".
$ver[15]."||".
$ver[16]."||".
$ver[17]."||".
$ver[18];
$date = date_create($ver[6]);
?>
<tr style="text-align: center;">
<td><?php echo date_format($date, 'd/m/Y H:i') ?></td>
<td><?php echo $ver[2] ?></td>
<td><?php echo $ver[1] ?></td>
<td><?php echo $ver[3] ?></td>
<td><?php echo $ver[5] ?></td>
<td><?php echo $ver[7] ?></td>
<td>
<a class="btn" data-toggle="modal"
data-target="#modalEdicion" onclick="agregaform('<?php echo $datos ?>'); editarformTrue();">
<i class='fas fa-eye' style='color:#007bff;'></i>
</a>
<a class="btn" data-toggle="modal"
data-target="#modalAlteracion" onclick="agregaformalt('<?php echo $datos ?>'); idTableAlt('<?php echo $ver[0] ?>')">
<i class='fas fa-file-medical' style='color:#F99922;'></i>
</a>
<a class="btn"
onclick="preguntarSiNo('<?php echo $ver[0] ?>')">
<i class='fas fa-trash-alt' style='color:#d9534f;'></i>
</a>
</td>
</tr>
<?php
}
?>
</table>
</div>
table-alteration.php (previous connection with server) - >
<table class="tableAlt table-striped"> <!-- TABLA ALTERACION -->
<thead>
<tr>
<th scope="col">Fecha/Hora</th>
<th scope="col">Lesion</th>
<th scope="col">Motivo</th>
<th></th>
</tr>
</thead>
<tbody>
<?php
$sqlquery="SELECT id_ingresos from ingresos";
$result=mysqli_query($conexion,$sqlquery);
while($ver=mysqli_fetch_row($result)){
$datos=$ver[0];
$sql="SELECT id_alteracion,motivo_alt,lesion_alt,fecha_alt,ingresos_id,id_ingresos from
alteracion,ingresos WHERE ingresos_id = '".$datos."' ORDER BY id_alteracion DESC";
$result=mysqli_query($conexion,$sql);
while($row=mysqli_fetch_row($result)){
$datos=$row[0]."||".
$row[1]."||".
$row[2]."||".
$row[3]."||".
$row[4]."||".
$row[5];
$date = date_create($row[3]);
?>
<tr style="text-align: center;">
<td><?php echo date_format($date, 'd/m/Y H:i') ?></td>
<td><?php echo $row[2] ?></td>
<td><?php echo $row[1] ?></td>
<td>
<a class="btn" data-dismiss="modal" data-toggle="modal"
data-target="#">
<i class='fas fa-eye' style='color:#007bff;'></i>
</a>
<a class="btn" data-dismiss="modal"
onclick="preguntarSiNo('<?php echo $row[0] ?>')">
<i class='fas fa-trash-alt' style='color:#d9534f;'></i>
</a>
</td>
</tr>
<?php
}}
?>
</tbody>
funciones.js - >
function agregardatosAlt(motivoalt,lesionalt,fechaalt){ // AGREGAR TABLA ALTERACION
cadena="motivoalt=" + motivoalt +
"&lesionalt=" + lesionalt +
"&fechaalt=" + fechaalt;
$.ajax({
type:"POST",
url:"php/agregarAlt.php",
data:cadena,
success:function(r){
if(r==1){
$('#tabla').load('componentes/tabla.php');
$('#tabla-detalles').load('componentes/tabla-detalles.php');
alertify.success("agregado con exito :)");
}else{
alertify.error("Fallo el servidor :(");
}
}
});
}
function aggregateformat (data) {// SELF-COMPLETE ALTERATION TABLE
d=datos.split('||');
$('#title').val(d[1] + ' ' + d[2] + ' ' + '(' + 'L.P.U.' + ' ' + d[3] + ')');
}
function idTableAlt () {
$('#tabla-alteracion').load('componentes/tabla-alteracion.php');
}