PHP - Poblar tabla JSON

 
Vista:

Poblar tabla JSON

Publicado por Nicolás (2 intervenciones) el 16/08/2021 22:17:44
Estoy realizando un CRUD con PHP, MySQL y otras herramientas para poder poblar mi tabla de información generado desde un JSON pero he probado varias maneras y no he podido poblar la informaión requerida. Me gustaria contar con ayuda para saber que hago mal.

En mi indice ademas del problema de llenar mi table tengo el problema que al apretar el button sumbit este me carga mi backend donde realizo las diferentes consultas.

index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php include "conn.php"; ?>
<!DOCTYPE html>
<html lang="en">
<head>
    <head>
		<?php include("head.php");?>
    </head>
    <body>
        <div class="navbar navbar-fixed-top">
            <div class="navbar-inner">
                <div class="container">
                    <a class="btn btn-navbar" data-toggle="collapse" data-target=".navbar-inverse-collapse">
                        <i class="icon-reorder shaded"></i></a><a class="brand" href="/visorpartes" >Visor Parte Digital</a>
 
 
                </div>
            </div>
            <!-- /navbar-inner -->
        </div><br />
 
            <div class="container">
            <h3 class="panel-title">Busqueda de partes malos</h3>
            <form class="" action="tester.php" method='get' id="busqueda" autocomplete="off">
    <fieldset>
 
      <div class="col-lg-12">
 
        <div class="col-lg-2 col-md-3 col-sm-10 form-group">
          <label for="name" class="control-label">Unidad policial</label>
          <input type="text" class="form-control" id="unidad_policial" name="unidad_policial" value='' placeholder="Unidad policial">
        </div>
        <div class="form-group col-lg-3 col-md-3">
            <div class="form-check">
                <label>
                    <input class="form-check-input" type="checkbox" id="ver_malo" name="ver_malo" value="1" > Ver parte malo
                </label>
            </div>
        </div>
      <div class="col-sm-12  form-group">
        <div class="">
          <button type="button" class="btn btn-default" onclick='resetForm($("#busqueda"));'>Cancelar</button>
          <button type="submit" class="btn btn-primary">Buscar</button>
        </div>
      </div>
    </fieldset>
  </form>
</div>
<div>
<table id="informe" class="table table-striped table-bordered table-mid" cellspacing="0" width="100%">
        <thead>
            <tr>
              <th>Id</th>
              <th>Archivo</th>
              <th>Fecha</th>
              <th>Estado</th>
              <th>Paso actual</th>
              <th>Ruta respaldo</th>
              <th class="text-center"> Acciones</th>
            </tr>
        </thead>
        <tfoot>
            <tr>
              <th>Id</th>
              <th>Archivo</th>
              <th>Fecha</th>
              <th>Estado</th>
              <th>Paso actual</th>
              <th>Ruta respaldo</th>
              <th class="text-center"> Acciones</th>
            </tr>
        </tfoot>
    </table>
</div>
 
 
 
 
 
 
 
 
 
 
            <!--/.container-->
 
        <!--/.wrapper--><br />
        <div class="footer span-12">
            <div class="container">
              <center> <b class="copyright"><a href="http://bpt.cl"> Blue Peaks SpA</a> &copy; <?php echo date("Y")?> Visor Parte Digital </b></center>
            </div>
        </div>
        <script src="bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
 
        <script src="datatables/jquery.dataTables.js"></script>
        <script src="datatables/dataTables.bootstrap.js"></script>
        <script>
            function resetForm($form){
                $form.find('input:text, input:password, input:file, select, textarea').val('');
                $form.find('input:radio, input:checkbox').removeAttr('checked').removeAtrr('selected');
            }
 
            $(document).ready(function() {
 
            var dataTable = $('#informe').DataTable( {
 
             "language":	{
                "sProcessing":     "Procesando...",
                "sLengthMenu":     "Mostrar _MENU_ registros",
                "sZeroRecords":    "No se encontraron resultados",
                "sEmptyTable":     "Ningún dato disponible en esta tabla",
                "sInfo":           "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros",
                "sInfoEmpty":      "Mostrando registros del 0 al 0 de un total de 0 registros",
                "sInfoFiltered":   "(filtrado de un total de _MAX_ registros)",
                "sInfoPostFix":    "",
                "searching":         false,
                "sUrl":            "",
                "sInfoThousands":  ",",
                "sLoadingRecords": "Cargando...",
                "oPaginate": {
                    "sFirst":    "Primero",
                    "sLast":     "Último",
                    "sNext":     "Siguiente",
                    "sPrevious": "Anterior"
                },
                "oAria": {
                    "sSortAscending":  ": Activar para ordenar la columna de manera ascendente",
                    "sSortDescending": ": Activar para ordenar la columna de manera descendente"
                }
            },
 
                "processing": true,
                "serverSide": true,
                "ajax":{
                    url :"tester.php", // json datasource
                    type: "post",  // method  , by default get
                    error: function(){  // error handling
                        $(".informe-error").html("");
                        $("#informe").append('<tbody class="employee-grid-error"><tr><th colspan="3">No data found in the server</th></tr></tbody>');
                        $("#informe_processing").css("display","none");
 
                    }
                }
            } );
        } );
 
        </script>
 
    </body>

En el index.php tengo problema en el sumbit ya que me realiza una carga al metodo tester.php y no refresca mi table ademas que no logro cargar la información a mi indice.

tester.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
 
 include "conn.php";
 
/* Database connection end */
 
$columns = array(
	// datatable column index  => database column name
		0 => 'id',
		1 => 'nombre_archivo',
		2 => 'created_at',
		3 => 'estado',
		4 => 'paso_actual',
		5 => 'ruta_respaldo'
	);
// storing  request (ie, get/post) global array to a variable
//$requestData= $_REQUEST;
$unidad_policial= $_GET['unidad_policial'];
$ver_malo= $_GET['ver_malo'];
//$unidad_policial=(isset($_REQUEST["unidad_policial"]) && $_REQUEST["unidad_policial"]!="");
//$ver_malos=(isset($_REQUEST["ver_malo"]) && $_REQUEST["ver_malo"]!="" ? $_REQUEST["ver_malo"] : 600);
//echo $unidad_policial;
$ver=isset($_GET['ver_malo']) ? "1" : "0";
 
$where="";
$where.= "WHERE paso_actual IN ('3-EN ERROR', '4-EN MALOS') ";
 
if($ver=="1"){
	$where.= " AND ver_malo = 'L'";
}
 
//$unidad_policial=$_REQUEST['unidad_policial'];
if(isset($unidad_policial) && $unidad_policial!="" ){
	$where.=" AND unidad_policial LIKE '".$unidad_policial."%' ";
}
 
$from=" FROM archivo ";
 
$query="SELECT id, nombre_archivo, created_at, estado, paso_actual, ruta_respaldo $from $where";
 
$query=$query. " ORDER BY unidad_policial DESC";
//echo $query;
 
$sql=mysqli_query($conn, $query) or die("tester.php: get PO");
 
$totalData = mysqli_num_rows($sql);
$totalFiltered = $totalData;
 
$data = array();
while( $row=mysqli_fetch_array($sql) ) {  // preparing an array
	$nestedData=array();
 
	$nestedData[] = $row["id"];
    $nestedData[] = $row["nombre_archivo"];
	$nestedData[] = $row["created_at"];
	$nestedData[] = $row["estado"];
    $nestedData[] = $row["paso_actual"];
    $nestedData[] = $row["ruta_respaldo"];
    $nestedData[] = '<td><center>
					 <a href="visualiza.php?path='.$row['ruta_respaldo'].'&file='.$row['nombre_archivo'].'"  data-toggle="tooltip" title="Ver" class="btn btn-sm btn-info"> <i class="menu-icon icon-file"></i> </a>
                     <a href="actualizar.php?id='.$row['id'].'"  data-toggle="tooltip" title="Editar" class="btn btn-sm btn-success"> <i class="menu-icon icon-edit"></i> </a>
				     </center></td>';
 
	$data[] = $nestedData;
    //action="update-edit.php" method="POST"
	//<a href="editar.php?id='.$row['id'].'"  data-toggle="tooltip" title="Ver" class="btn btn-sm btn-info"> <i class="menu-icon icon-file"></i> </a>
}
 
 
 
$json_data = array(
			"draw"            => intval( $requestData['draw'] ),   // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw.
			"recordsTotal"    => intval( $totalData ),  // total number of records
			"recordsFiltered" => intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData
			"data"            => $data   // total data array
			);
 
echo json_encode($json_data);  // send data as json format
 
?>
En este archivo realizo la conexión a mi db y entrego la informacíon de la consulta realizada pero como explico tengo problema al cargar la tabla con jquery ya que no me manejo de buena manera me gustaria contar con ayuda y asi poder aprender mas
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder