PHP - Agregar datatable en un reporte en php

 
Vista:
Imágen de perfil de Matias
Val: 7
Ha aumentado su posición en 24 puestos en PHP (en relación al último mes)
Gráfica de PHP

Agregar datatable en un reporte en php

Publicado por Matias (4 intervenciones) el 21/04/2021 20:20:07
buenas gente soy nuevo en el mundo php y estoy modificando un codigo que genera reportes, quiero utilizar datatable que es un plugin para exportar e imprimir tablas de sql con javascript.
yo ya tengo creado el reporte me muestra los datos en el navegador perfecto, ahora le quiero agregar el codigo de datatable para poder exportar los datos que muestra en mi reporte, les copio el codigo de la pagina completa reporte.php para ver si se les ocurre algo, espero que me puedan ayudar, muchas gracias!!


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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<?php
    $title ="Reportes | ";
    include "head.php";
    include "sidebar.php";
 
    $projects = mysqli_query($con, "select * from project");
    $sectores =mysqli_query($con, "select * from sector");
	$user =mysqli_query($con, "select * from user");
    $priorities =mysqli_query($con, "select * from priority");
    $statuses =mysqli_query($con, "select * from status");
    $kinds =mysqli_query($con, "select * from kind");
    $categories =mysqli_query($con, "select * from category");
	$equipamientos =mysqli_query($con, "select * from equipamiento");
	$ticket1 =mysqli_query($con, "select id from ticket");
	$ticket =mysqli_query($con, "select * from ticket");
	$sector =mysqli_query($con, "select * from sector");
 
?>
 
    <div class="right_col" role="main"><!-- page content -->
        <div class="">
            <div class="page-title">
                <div class="clearfix"></div>
                <div class="col-md-12 col-sm-12 col-xs-12">
                    <div class="x_panel">
                        <div class="x_title">
                            <h2>Informe de mantenimiento -* usando datatable</h2>
                            <ul class="nav navbar-right panel_toolbox">
                                <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                                </li>
                                <li><a class="close-link"><i class="fa fa-close"></i></a>
                                </li>
                            </ul>
                            <div class="clearfix"></div>
                        </div>
 
                        <!-- form search -->
                        <form class="form-horizontal" role="form">
                            <input type="hidden" name="view" value="reports">
                            <div class="form-group">
                            <div class="col-lg-3">
                                <div class="input-group">
                                    <span class="input-group-addon"><i class="fa fa-support"></i></span>
                                    <select name="category_id" class="form-control">
                                    <option value="">Sector</option>
                                      <?php foreach($categories as $p):?>
                                        <option value="<?php echo $p['id']; ?>" <?php if(isset($_GET["category_id"]) && $_GET["category_id"]==$p['id']){ echo "selected"; } ?>><?php echo $p['name']; ?></option>
                                      <?php endforeach; ?>
                                    </select>
                                </div>
                            </div>
                            <div class="col-lg-3">
                                <div class="input-group">
                                    <span class="input-group-addon"><i class="fa fa-support"></i></span>
                                    <select name="priority_id" class="form-control">
                                    <option value="">PRIORIDAD</option>
                                      <?php foreach($priorities as $p):?>
                                        <option value="<?php echo $p['id']; ?>" <?php if(isset($_GET["priority_id"]) && $_GET["priority_id"]==$p['id']){ echo "selected"; } ?>><?php echo $p['name']; ?></option>
                                      <?php endforeach; ?>
                                    </select>
                                </div>
                            </div>
                            <div class="col-lg-3">
                                <div class="input-group input-group-sm mb-3">
                                  <span class="input-group-addon">DESDE</span>
                                  <input type="date" name="start_at" value="<?php if(isset($_GET["start_at"]) && $_GET["start_at"]!=""){ echo $_GET["start_at"]; } ?>" class="form-control" placeholder="Palabra clave">
                                </div>
                            </div>
                            <div class="col-lg-3">
                                <div class="input-group input-group-sm mb-3">
                                  <span class="input-group-addon">HASTA</span>
                                  <input type="date" name="finish_at" value="<?php if(isset($_GET["finish_at"]) && $_GET["finish_at"]!=""){ echo $_GET["finish_at"]; } ?>" class="form-control" placeholder="Palabra clave">
                                </div>
                            </div>
                            </div>
                            <div class="form-group">
                                <div class="col-lg-3">
                                    <div class="input-group">
                                        <span class="input-group-addon">ESTADO</span>
                                        <select name="status_id" class="form-control">
										<option value="">Todos</option>
                                          <?php foreach($statuses as $p):?>
                                            <option value="<?php echo $p['id']; ?>" <?php if(isset($_GET["status_id"]) && $_GET["status_id"]==$p['id']){ echo "selected"; } ?>><?php echo $p['name']; ?></option>
                                          <?php endforeach; ?>
                                        </select>
                                    </div>
                                </div>
                                <div class="col-lg-3">
                                    <div class="input-group">
                                        <span class="input-group-addon">TIPO</span>
                                        <select name="kind_id" class="form-control">
										<option value="">Todos</option>
                                          <?php foreach($kinds as $p):?>
                                            <option value="<?php echo $p['id']; ?>" <?php if(isset($_GET["kind_id"]) && $_GET["kind_id"]==$p['id']){ echo "selected"; } ?>><?php echo $p['name']; ?></option>
                                          <?php endforeach; ?>
                                        </select>
                                    </div>
                                </div>
                                <div class="row">
								  <div class="col-sm-3"></div>
								  <div class="col-sm-6"><button class="btn btn-primary btn-block">Procesar</button></div>
								  <div class="col-sm-3"></div>
								</div>
 
 
                            </div>
                        </form>
                        <!-- end form search -->
 
                         <?php
                                        $users= array();
                                        if((isset($_GET["status_id"]) && isset($_GET["kind_id"]) && isset($_GET["category_id"]) && isset($_GET["priority_id"]) && isset($_GET["start_at"]) && isset($_GET["finish_at"]) ) && ($_GET["status_id"]!="" ||$_GET["kind_id"]!="" || $_GET["category_id"]!="" || $_GET["priority_id"]!="" || ($_GET["start_at"]!="" && $_GET["finish_at"]!="") ) ) {
                                        $sql = "select * from ticket where ";
                                        if($_GET["status_id"]!=""){
                                            $sql .= " status_id = ".$_GET["status_id"];
                                        }
 
                                        if($_GET["kind_id"]!=""){
                                        if($_GET["status_id"]!=""){
                                            $sql .= " and ";
                                        }
                                            $sql .= " kind_id = ".$_GET["kind_id"];
                                        }
 
 
                                        if($_GET["category_id"]!=""){
                                        if($_GET["status_id"]!=""||$_GET["kind_id"]!=""){
                                            $sql .= " and ";
                                        }
                                            $sql .= " category_id = ".$_GET["category_id"];
                                        }
 
                                        if($_GET["priority_id"]!=""){
                                        if($_GET["status_id"]!=""||$_GET["category_id"]!=""||$_GET["kind_id"]!=""){
                                            $sql .= " and ";
                                        }
 
                                            $sql .= " priority_id = ".$_GET["priority_id"];
                                        }
 
                                        if($_GET["start_at"]!="" && $_GET["finish_at"]){
                                        if($_GET["status_id"]!=""||$_GET["category_id"]!="" ||$_GET["priority_id"]!="" ||$_GET["kind_id"]!="" ){
                                            $sql .= " and ";
                                        }
 
                                            $sql .= " ( date_at >= \"".$_GET["start_at"]."\" and date_at <= \"".$_GET["finish_at"]."\" ) ";
                                        }
 
                                                $users = mysqli_query($con, $sql);
 
                                        }else{
                                                $users = mysqli_query($con, "select * from ticket order by created_at desc");
 
                                        }
 
                            if(@mysqli_num_rows($users)>0){
                                // si hay reportes
                                $_SESSION["report_data"] = $users;
                            ?>
        <div class="x_content">
            <div class="table-responsive">
                <table class="table table-bordered table-hover">
                    <thead>
                        <th>Asunto</th>
                        <th>Orden de trabajo</th>
                        <th>Deposito</th>
						<th>Prioridad</th>
                        <th>Estado</th>
                        <th>Fecha</th>
                        <th>Ultima Actualizacion</th>
                    </thead>
            <?php
            $total = 0;
            foreach($users as $user){
                $category_id=$user['category_id'];
                $priority_id=$user['priority_id'];
                $kind_id=$user['kind_id'];
                $status_id=$user['status_id'];
 
 
                $status=mysqli_query($con, "select * from status where id=$status_id");
                $category=mysqli_query($con, "select * from category where id=$category_id");
                $kinds = mysqli_query($con,"select * from kind where id=$kind_id");
                $medic = mysqli_query($con,"select * from priority where id=$priority_id");
 
 
                ?>
                <tr>
                <td><?php echo $user['title'] ?></td>
                <?php foreach($kinds as $kind){?>
                <td><?php echo $kind['name'] ?></td>
                <?php } ?>
                <?php foreach($category as $cat){?>
                <td><?php echo $cat['name']; ?></td>
                <?php } ?>
                 <?php foreach($medic as $medics){?>
                <td><?php echo $medics['name']; ?></td>
                <?php } ?>
                <?php foreach($status as $stat){?>
                <td><?php echo $stat['name']; ?></td>
                 <?php } ?>
                <td><?php echo $user['created_at']; ?></td>
                <td><?php echo $user['updated_at']; ?></td>
                </tr>
             <?php
 
                }
 
              ?>
       <?php
 
        }else{
            echo "<p class='alert alert-danger'><strong>Aviso! </strong>No hay datos para mostrar!</p>";
        }
 
 
        ?>
     </table>
 
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div><!-- /page content -->
 
<?php include "footer.php" ?>




reporte_php
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