PHP - FPDF masivo desde Msql

 
Vista:
Imágen de perfil de Javier

FPDF masivo desde Msql

Publicado por Javier (11 intervenciones) el 01/06/2017 12:24:24
Buenos días,

Estoy intentando crear PDF masivos con FPDF desde MySQL y PHP. Lo que deseo es que cogiendo el ID de la tabla jornada me cree tantos documentos con los datos de tantos id como existan en la tabla y no solo eso, sino que me los guarde con nombres diferente. Esta parte es la única que he conseguido pero con los mismos datos.


He intentado con un while, para el bucle, pero solo me da errores. Actualemente lo dejo como me funciona, a falta de crear el bucle que lo recorra y la sql.


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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
<?php
session_start();
/*Eliminamos los errores del notice*/
error_reporting(-1);
require("../loginmodel.php");
if(!isset($_SESSION["session_username"]))
header("location: ../index.php");
 
?>
 
<?php
header("Content-Type: text/html; utf-8");
html_entity_decode("&aacute;");
require('../fpdf/fpdf.php');
require("../conexionBD.php");
 
/*inicializamos*/
$pdf = new FPDF();
/*Crea una nueva página*/
$pdf->AddPage();
 
/*Nombre de la fuente, tipología, tamaño */
$pdf->SetFont('Arial','B',16);
/*direccion, altura, ancho, ubicacion,formato*/
class PDF extends FPDF
{
// Cabecera de página
function Header()
{
    // Logo
    $this->Image('../img/logo.png',10,8,33);
    // Arial bold 15
    $this->SetFont('Arial','B',15);
    $this->Ln(10);
    // Movernos a la derecha
    $this->Cell(80);
    // Título
    $this->Cell(30,5,utf8_decode('ACTA "LIGA MADRID 2016-2017 - Madrid Rio"'),0,0,'C');
    // Salto de línea
    $this->Ln(20);
}
 
function Body()
{
require("../conexionBD.php");
 
 
 
$tabla_jornada =mysqli_query($conexion, "SELECT * FROM jornada Where id = 'id' ");
$data3 = mysqli_fetch_array($tabla_jornada);
 
$equipolocal     =  $data3["id_eq_local"];
$equipovisitante =  $data3["id_eq_visitante"];
 
 
$equipo1 =mysqli_query($conexion, "SELECT * FROM equipos a inner join jugadores b on a.id_equipo=b.id_equipo where a.id_equipo = '$equipolocal'");
$data = mysqli_fetch_array($equipo1);
 
 
$equipo2 =mysqli_query($conexion, "SELECT * FROM equipos a inner join jugadores b on a.id_equipo=b.id_equipo where a.id_equipo = '$equipovisitante'");
$data2 = mysqli_fetch_array($equipo2);
 
 
$tabla_jornada =mysqli_query($conexion, "SELECT * FROM jornada Where id = (Select Max(id) from jornada)");
$data3 = mysqli_fetch_array($tabla_jornada);
 
 
 
/*$partidos =mysqli_query($conexion, "SELECT * FROM jornada Where id = (Select Max(id) from jornada)");
$data=mysqli_fetch_array($partidos);*/
 
$fechaBD = $data3["fecha"];
$fecha = date("d-m-Y",strtotime($fechaBD));
 
 
/*FECHA*/
    $this->SetFont('Arial','B',8);
 
    /*Tamaño de la celda, altura, nombre, borde (0 ó 1)*/
    $this->SetFillColor(37, 127, 210);
    $this->Cell(25,6,'Fecha:',1,0,'L',true);
    $this->SetFont('Arial','I',8);
    $this->Cell(25,6,$fecha,1);
 
/*DEPORTE*/
    $this->SetFillColor(37, 127, 210);
    $this->Cell(60,6,'',0);
    $this->SetFont('Arial','B',8);
    $this->Cell(25,6,utf8_decode('Grupo Horario:'),1,0,'L',true);
    $this->SetFont('Arial','I',8);
    $this->Cell(50,6,utf8_decode($data3["grupo_horario"]),1);
 
/*HORA*/
    $this->Ln();
    $this->SetFillColor(37, 127, 210);
    $this->SetFont('Arial','B',8);
    $this->Cell(25,6,'Hora:',1,0,'L',true);
    $this->SetFont('Arial','I',8);
    $this->Cell(25,6,$data3["hora"],1);
 
 /* LUGAR*/
    $this->SetFillColor(37, 127, 210);
    $this->Cell(60,6,'',0);
    $this->SetFont('Arial','B',8);
    $this->Cell(25,6,utf8_decode('División/Grupo'),1,0,'L',true);
    $this->SetFont('Arial','I',8);
    $this->Cell(50,6,utf8_decode($data3["division"].'/'),1);
 
/*JORNADA*/
    $this->Ln();
    $this->SetFillColor(37, 127, 210);
    $this->SetFont('Arial','B',8);
    $this->Cell(25,6,'Jornada:',1,0,'L',true);
    $this->SetFont('Arial','I',8);
    $this->Cell(25,6,utf8_decode($data3["jornada"]),1);
 
/*CAMPO*/
    $this->SetFillColor(37, 127, 210);
    $this->Cell(60,6,'',0);
    $this->SetFont('Arial','B',8);
    $this->Cell(25,6,'Campo:',1,0,'L',true);
    $this->SetFont('Arial','I',8);
    $this->Cell(50,6,utf8_decode($data3["campo"]),1);
 
 
 
/*ÁRBITROS*/
$this->Ln();
    $this->SetFillColor(37, 127, 210);
    $this->SetFont('Arial','B',8);
    $this->Cell(25,6,utf8_decode('Árbitros:'),1,0,'L',true);
    $this->SetFont('Arial','I',8);
    $this->Cell(160,6,'',1);
 
 
/*EQUIPO 1*/
 
$this->Ln(15);
    $this->SetFillColor(37, 127, 210);
    $this->SetFont('Arial','B',8);
    $this->Cell(25,6,'Equipo Local:',1,0,'L',true);
    $this->SetFont('Arial','I',8);
    $this->Cell(68,6,utf8_decode($data["nombre_equipo"]),1);
 
/*EQUIPO 2*/
    $this->SetFillColor(37, 127, 210);
    $this->SetFont('Arial','B',8);
    $this->Cell(25,6,'Equipo Visitante:',1,0,'L',true);
    $this->SetFont('Arial','I',8);
    $this->Cell(68,6,utf8_decode($data2["nombre_equipo"]),1);
 
 
/*Equipacion Local*/
$this->Ln();
    $this->SetFillColor(37, 127, 210);
    $this->SetFont('Arial','B',8);
    $this->Cell(25,6,'Equipacion Lc.',1,0,'L',true);
    $this->SetFont('Arial','I',8);
    $this->Cell(68,6,utf8_decode($data["color_local"]),1);
 
 
/*Equipacion Visitante*/
    $this->SetFillColor(37, 127, 210);
    $this->SetFont('Arial','B',8);
    $this->Cell(25,6,'Equipacion vist.',1,0,'L',true);
    $this->SetFont('Arial','I',8);
    $this->Cell(68,6,utf8_decode($data2["color_local"]),1);
 
/*COLUMNAS 1º*/
$this->Ln();
$this->SetFillColor(37, 127, 210);
$this->SetFont('Arial','B',8);
$this->Cell(10,7,'Dorsal',1,0,'L', true);
$this->Cell(47,7,'Nombre',1,0,'L', true);
$this->Cell(12,7,'Goles',1,0,'L', true);
$this->Cell(12,7,'Portero',1,0,'L', true);
$this->Cell(12,7,'Tarjetas',1,0,'L', true);
 
/*COLUMNAS 1º*/
$this->SetFillColor(37, 127, 210);
$this->SetFont('Arial','B',8);
$this->Cell(10,7,'Dorsal',1,0,'L', true);
$this->Cell(47,7,'Nombre',1,0,'L', true);
$this->Cell(12,7,'Goles',1,0,'L', true);
$this->Cell(12,7,'Portero',1,0,'L', true);
$this->Cell(12,7,'Tarjetas',1,0,'L', true);
 
 
/*JUGADORES*/
 
$equipo1 =mysqli_query($conexion, "SELECT * FROM equipos a inner join jugadores b on a.id_equipo=b.id_equipo where a.id_equipo = '$equipolocal' order by b.dorsal desc");
$equipo2 =mysqli_query($conexion, "SELECT * FROM equipos a inner join jugadores b on a.id_equipo=b.id_equipo where a.id_equipo = '$equipovisitante' order by b.dorsal desc");
 
while($data=mysqli_fetch_array($equipo1) and $data2=mysqli_fetch_array($equipo2)){
 
 
$nombre=$data["nombre"];
$apellido=$data["apellidos"];
 
 
 
$nombre2=$data2["nombre"];
$apellido2=$data2["apellidos"];
 
$this->Ln();
$this->SetFont('Arial','I',8);
$this->Cell(10,7,$data["dorsal"],1);
$this->Cell(47,7,utf8_decode($nombre.' '.$apellido),1);
$this->Cell(12,7,'',1);
$this->Cell(12,7,'',1);
$this->Cell(12,7,'',1);
 
 
 
$this->SetFont('Arial','I',8);
$this->Cell(10,7,$data2["dorsal"],1);
$this->Cell(47,7,utf8_decode($nombre2.' '.$apellido2),1);
$this->Cell(12,7,'',1);
$this->Cell(12,7,'',1);
$this->Cell(12,7,'',1);
 
}
 
/*Delegados*/
$delegados1 =mysqli_query($conexion, "SELECT * FROM equipos a inner join delegados b on a.id_equipo=b.id_equipo where a.id_equipo = '$equipolocal'");
$delegados2 =mysqli_query($conexion, "SELECT * FROM equipos a inner join delegados b on a.id_equipo=b.id_equipo where a.id_equipo = '$equipovisitante'");
 
while($data3=mysqli_fetch_array($delegados1) and $data4=mysqli_fetch_array($delegados2)){
 
 
$nombre3=$data3["nombre"];
$apellido3=$data3["apellidos"];
 
 
 
$nombre4=$data4["nombre"];
$apellido4=$data4["apellidos"];
 
$this->Ln();
$this->SetFont('Arial','I',8);
$this->Cell(40,7,utf8_decode($nombre3.' '.$apellido3),1);
$this->Cell(53,7,utf8_decode('DELEGADO'),1);
 
 
 
$this->SetFont('Arial','I',8);
$this->Cell(40,7,utf8_decode($nombre4.' '.$apellido4),1);
$this->Cell(53,7,utf8_decode('DELEGADO'),1);
 
}
 
 
 
 
 
 
/*PARTE FINAL*/
 
 
$this->Ln(3);
 
/*RESULTADO EQUIPO*/
 
$this->Ln();
    $this->SetFont('Arial','B',8);
    $this->Cell(5,7,utf8_decode(''),0);
    $this->Cell(25,7,utf8_decode('Resultado equipo local: '),0   );
    $this->Cell(30,7,utf8_decode(''),0);
    $this->Cell(14,7,utf8_decode(''),1);
    $this->SetFont('Arial','B',8);
 
    $this->Cell(30,10,utf8_decode(''),0);
 
 
/*EQUIPO 2*/
  $this->SetFont('Arial','B',8);
 
    $this->Cell(5,7,utf8_decode(''),0);
    $this->Cell(25,7,utf8_decode('Resultado equipo Visitante: '),0   );
    $this->Cell(30,7,utf8_decode(''),0);
    $this->Cell(14,7,utf8_decode(''),1);
    $this->SetFont('Arial','B',8);
 
    $this->Cell(30,10,utf8_decode(''),0);
 
 
 
    /*Observaciones*/
 
$this->Ln();
    $this->SetFont('Arial','B',8);
    $this->Cell(184,15,utf8_decode('Observaciones:'),1);
 
 
 
    /*Firmas del capitan*/
    $this->Ln(20);
    $this->SetFont('Arial','B',8);
    $this->Cell(61,10,utf8_decode('Firma capitán:'),1);
    $this->Cell(61.5,10,utf8_decode('Firma árbitro:'),1);
    $this->Cell(61.5,10,utf8_decode('Firma capitán:'),1);
 
 
 
 
 
 
/*Muestro el id del partido*/
$this->SetY(15);
$this->SetX(-15);
 $this->Cell(30,7,utf8_decode($data3["id"]),0);
mysqli_close($conexion);
}
 
 
 
 
 
// Pie de página
function Footer()
{
    // Posición: a 1,5 cm del final
    $this->SetY(-15);
    // Arial italic 8
    $this->SetFont('Arial','I',8);
    // Número de página
    /*$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');*/
}
}
 
 
//Aquí simplemente hago una prueba, pero no es lo correcto
$id = 1;
 
while($id<5){
 
$imp =mysqli_query($conexion, "SELECT * FROM jornada Where id = '$id' ");
$dataimp = mysqli_fetch_array($imp);
 
// Creación del objeto de la clase heredada
$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->body();
$pdf->Output('actas-partidos/partido Nº'.utf8_decode($dataimp["id"]).'.pdf', 'F');
 
$id++;
 
 }
?>

Muchas gracias!
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

FPDF masivo desde Msql

Publicado por Kristian Arenas (1 intervención) el 15/03/2022 18:42:32
Buenas, disculpa por revivir este tema, lograste conseguir lo que intentabas? me gustaria saber como lo lograste.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar