
Ayuda con la libreria fpdf no se imprime una variable
Publicado por Daniel Alejandro (1 intervención) el 23/08/2017 17:49:45
Hola a todos soy nuevo en este foro y también en PHP, he estado trabajando con la librería fpdf y me ha ido bastante bien pero me he topado con el obstáculo de que no puedo imprimir la variable cliente de mi base de datos con fpdf. Agradecería mucho su ayuda. Les dejo mi código.
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
<?php
require('fpdf/fpdf.php');
class Tabla {
public function all() {
try {
$id_pedido = $_GET['id_pedido'];
include_once("resource/Database.php");
$sql = "SELECT producto, cantidad, unidad FROM capturar_pedido WHERE id_pedido=$id_pedido";
$query = $db->prepare($sql);
$query->execute();
$tabla = $query->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
//echo "Exeption: " .$e->getMessage();
$result = false;
}
$query = null;
$db = null;
return $tabla;
}
public function cliente() {
$id_pedido = $_GET['id_pedido'];
include_once("resource/Database.php");
$q= $db->query("SELECT cliente FROM capturar_pedido WHERE id_pedido=$id_pedido");
$cliente = $q->fetchColumn();
return $cliente;
}
}
class TablaPDF extends FPDF {
// Page header
function Header()
{
}
function Footer()
{
// Position at 1.5 cm from bottom
$this->SetY(-30);
// Arial italic 8
$this->SetFont('Arial','I',8);
// Page number
$this->Cell(0,10,'Nombre y firma de quien entrega',0,0,'L');
// Position at 1.5 cm from bottom
$this->SetY(-35);
// Arial italic 8
$this->SetFont('Arial','I',8);
// Page number
$this->Cell(0,10,'__________________________',0,0,'L');
// Position at 1.5 cm from bottom
$this->SetY(-30);
// Arial italic 8
$this->SetFont('Arial','I',8);
// Page number
$this->Cell(0,10,'Nombre y firma de quien autoriza',0,0,'C');
// Position at 1.5 cm from bottom
$this->SetY(-35);
// Arial italic 8
$this->SetFont('Arial','I',8);
// Page number
$this->Cell(0,10,'__________________________',0,0,'C');
// Position at 1.5 cm from bottom
$this->SetY(-30);
// Arial italic 8
$this->SetFont('Arial','I',8);
// Page number
$this->Cell(0,10,'Nombre y firma de quien recibe',0,0,'R');
// Position at 1.5 cm from bottom
$this->SetY(-35);
// Arial italic 8
$this->SetFont('Arial','I',8);
// Page number
$this->Cell(0,10,'__________________________',0,0,'R');
}
// Create basic table
public function CreateTable($header, $data)
{
// Header
$this->SetFillColor(255);
$this->SetTextColor(0);
$this->SetFont('','B');
foreach ($header as $col) {
//Cell(float w [, float h [, string txt [, mixed border [, int ln [, string align [, boolean fill [, mixed link]]]]]]])
$this->Cell($col[1], 10, $col[0], 1, 0, 'L', true);
}
$this->Ln();
// Data
$this->SetFillColor(255);
$this->SetTextColor(0);
$this->SetFont('');
foreach ($data as $row)
{
$i = 0;
foreach ($row as $field) {
$this->Cell($header[$i][1], 6, $field, 1, 0, 'L', true);
$i++;
}
$this->Ln();
}
}
}
// Column headings
$header = array(
array('Descripcion del material', 50),
array('cantidad', 50),
array('unidad', 50),
array('observaciones', 50)
);
// Get data
$tabla = new Tabla();
$data = $tabla->all();
$cliente = $tabla->cliente();
$pdf = new TablaPDF();
$pdf->SetFont('Arial', '', 12);
$pdf->AddPage();
$pdf->CreateTable($header,$data);
$pdf->SetFont('Arial','B',16);
$pdf->SetFont('');
$pdf->Cell(40,10,'Destino: ');
$pdf->Cell(40,10,$cliente);
$pdf->Output();
Valora esta pregunta


0