Na plaatsen IF ELSE regels werkt TCPdf script niet meer
Echter dan werkt het script niet meer, m.a.w. er wordt geen document gemaakt.
Code (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
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
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
<?php
if (session_id() == "") session_start(); // if no active session we start a new one
//ini_set("memory_limit","30M");
error_reporting(E_ALL ^E_NOTICE);
ini_set('display_errors', 1);
error_reporting(E_ALL ^E_NOTICE);
// First get some data from a database table
include("datacon.php");
include("include/functions.php");
include("tcPDF_inc.php");
// tcPDF scripts used once
require_once('../tcpdf/config/lang/eng.php');
require_once('../tcpdf/tcpdf.php');
// Extend the TCPDF class to create custom Header and Footer
class MYPDF extends TCPDF {
//Page header
function Header() {
// Logo
$this->SetTextColor(0, 0, 0); // Set color
$this->SetFont('helvetica', 'B', 25); // Set font
// Title
// $this->Cell(0, 0, 'Accommodation overview', 0, false, 'C', 0, 'L', 0, false, 'M', 'M');
$this->Cell(0, 0, 'Accommodation overview', 0, false, 'L', 0, '', 0, false, ' ', ' ');
$image_file = 'images/Header_Brief.png';
$this->Image($image_file, 0, 6, 210, '', 'PNG', '', 'T', false, 300, '', false, false, 0, false, false, false);
}
// Page footer
function Footer() {
$datum = date('l jS \of F Y \a\t h:i:s A');
$Pagina = 'Page '.$this->getAliasNumPage().' from '.$this->getAliasNbPages();
$footerDateText = $Pagina.' - This document is created on '.$datum;
$this->SetY(-15);
$this->SetTextColor(0, 0, 0);
$this->SetFont('helvetica', ' ', 7);
$this->Cell(0,0, $footerDateText,' ',1,'R');
$this->SetFont('helvetica', ' ', 8);
$this->Cell(0,0, 'Stichting CCI Boekelo Postbus 535 7500AM Enschede','T',1,'L');
$this->Cell(0,0, 'T +31(0)53-4282831 F +31(0)53-4282851 [email protected] www.military-boekelo.nl',' ',1,'L');
}
}
// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Harry H. Arends');
$pdf->SetTitle('Stable Management Accommodation Overview');
$pdf->SetSubject('Stable Management Accommodation Overview');
$pdf->SetKeywords('Eventing, Military, CCI***, Boekelo, Enschede, Netherlands, FEI');
// *** Set PDF protection (encryption) *********************
//$pdf->SetProtection($permissions=array('modify', 'copy'), $user_pass='', $owner_pass=null, $mode=0, $pubkeys=null);
$pdf->SetProtection($permissions=array(), $user_pass='', $owner_pass=null, $mode=0, $pubkeys=null);
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_width, PDF_HEADER_TITLE, PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default mono-spaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//set margins
//$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
//$pdf->SetMargins(PDF_MARGIN_LEFT, 49, PDF_MARGIN_RIGHT);
$pdf->SetMargins(PDF_MARGIN_LEFT, 49, 10);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
//set some language-dependent strings
$pdf->setLanguageArray($l);
// ---------------------------------------------------------
$pdf->setJPEGQuality(75); // set JPEG quality
$pdf->SetFont('helvetica', '', 10); // set font
$pdf->AddPage(); // add a page
// get all the needed data from the tables
$sqlCombination = "
SELECT person.*, horse.*, 2010Combination.*
FROM FEIPerson AS person
INNER JOIN 2010Combination ON person.fei_id = 2010Combination.personFEIid
INNER JOIN FEIHorse horse ON horse.fei_id = 2010Combination.horseFEIid
ORDER BY person.competing_for_country, 2010Combination.compNumber ASC ";
$Result = mysql_query($sqlCombination);
if(!$Result) {
$html = 'There is een error opening table for listing Combinations; '.mysql_error();
$pdf->writeHTML($html, true, false, true, false, ' ');
}
$numberCombination = mysql_affected_rows();
if(!$result || ($numberCombination < 0)) { }
elseif($numberCombination > 0) {
for($i=0; $i<$numberCombination; $i++) {
$Row = mysql_fetch_assoc($Result);
$sqlCountry = "SELECT e_country FROM country WHERE ISO_A3 = '".$Row['competing_for_country']."'";
if (!(@ $resultCountry = mysql_query($sqlCountry))) {
$html = 'There was an error running your query: '.mysql_error();
$pdf->writeHTML($html, true, false, true, false, ' ');
}
$country_name = mysql_result($resultCountry, 0, e_country);
$pdf->SetFont('arialunicid0', '', 9);
$pdf->SetFont('helvetica', '', 9);
if($riderNF != $Row['competing_for_country']) {
$html = '<br /><br /><img border="0" src="images/Flags/'.$country_name.'.png" height="20"> <font size="+4"><b>'.$country_name.'</b></font> ('.$Row['competing_for_country'].')<br />
<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<th width="18"> </th>
<th width="175">Rider</th>
<!--th width="210">Horse</th--><!-- In 2015 vervallen -->
<th width="50">Bad Boekelo</th>
<th width="50">Caravan</th>
<th width="175">Groom</th>
</tr>
</table>';
$pdf->writeHTMLCell(0, 0, '', '', $html, 'B', 1, 0, true, 'L', false);
}
$html = '<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td width="25"> '.$Row[compNumber].'</td>
<td width="175"> '.$Row['first_name'].' '.ucwords(strtolower($Row['family_name'])).'</td>
<!--td width="210"> '.$Row['complete_name'].'</td--><!-- In 2015 vervallen -->';
if($Row['stayHorseBox'] == 'Yes')
{ $html = $html.'<td width="50" > Lorry </td>'; }
else if($Row['appartmentBB'] == 'No')
{ $html = $html.'<td width="50" > No </td>'; }
else if($Row['appartmentNumber'] == 0)
{ $html = $html.'<td width="50" border="1"></td>'; }
else
{ $html = $html.'<td width="50" >'.$Row['appartmentNumber'].'</td>'; }
if($Row['accomGroom'] == 'No')
{ $html = $html.'<td width="50" > No </td>'; }
else
if($Row['caravanNumber'] == 0)
{ $html = $html.'<td width="50" border="1"></td>'; }
else
{ $html = $html.'<td width="50"> '.$Row['caravanNumber'].' </td>'; }
if($Row['genderGroom'] == 'Female') {$genderGroom = '(F)';} else { $genderGroom = '(M)'; }
$html = $html.'<td width="175"> '.$Row['nameGroom'].' '.$genderGroom.' </td>
</tr>
</table>';
$pdf->writeHTML($html, false, false, true, false, ' ');
// Add newpage if next country
/*
if($riderNF == $Row['competing_for_country']
{ }
else
{ $pdf->AddPage(); }
*/
$riderNF = $Row['competing_for_country'];
}
} else {
$html = 'No records found.';
$pdf->writeHTML($html, true, false, true, false, ' ');
}
//Close and output PDF document
$pdf->Output('AccomodationOverview.pdf', 'I');
?>
if (session_id() == "") session_start(); // if no active session we start a new one
//ini_set("memory_limit","30M");
error_reporting(E_ALL ^E_NOTICE);
ini_set('display_errors', 1);
error_reporting(E_ALL ^E_NOTICE);
// First get some data from a database table
include("datacon.php");
include("include/functions.php");
include("tcPDF_inc.php");
// tcPDF scripts used once
require_once('../tcpdf/config/lang/eng.php');
require_once('../tcpdf/tcpdf.php');
// Extend the TCPDF class to create custom Header and Footer
class MYPDF extends TCPDF {
//Page header
function Header() {
// Logo
$this->SetTextColor(0, 0, 0); // Set color
$this->SetFont('helvetica', 'B', 25); // Set font
// Title
// $this->Cell(0, 0, 'Accommodation overview', 0, false, 'C', 0, 'L', 0, false, 'M', 'M');
$this->Cell(0, 0, 'Accommodation overview', 0, false, 'L', 0, '', 0, false, ' ', ' ');
$image_file = 'images/Header_Brief.png';
$this->Image($image_file, 0, 6, 210, '', 'PNG', '', 'T', false, 300, '', false, false, 0, false, false, false);
}
// Page footer
function Footer() {
$datum = date('l jS \of F Y \a\t h:i:s A');
$Pagina = 'Page '.$this->getAliasNumPage().' from '.$this->getAliasNbPages();
$footerDateText = $Pagina.' - This document is created on '.$datum;
$this->SetY(-15);
$this->SetTextColor(0, 0, 0);
$this->SetFont('helvetica', ' ', 7);
$this->Cell(0,0, $footerDateText,' ',1,'R');
$this->SetFont('helvetica', ' ', 8);
$this->Cell(0,0, 'Stichting CCI Boekelo Postbus 535 7500AM Enschede','T',1,'L');
$this->Cell(0,0, 'T +31(0)53-4282831 F +31(0)53-4282851 [email protected] www.military-boekelo.nl',' ',1,'L');
}
}
// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Harry H. Arends');
$pdf->SetTitle('Stable Management Accommodation Overview');
$pdf->SetSubject('Stable Management Accommodation Overview');
$pdf->SetKeywords('Eventing, Military, CCI***, Boekelo, Enschede, Netherlands, FEI');
// *** Set PDF protection (encryption) *********************
//$pdf->SetProtection($permissions=array('modify', 'copy'), $user_pass='', $owner_pass=null, $mode=0, $pubkeys=null);
$pdf->SetProtection($permissions=array(), $user_pass='', $owner_pass=null, $mode=0, $pubkeys=null);
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_width, PDF_HEADER_TITLE, PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default mono-spaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//set margins
//$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
//$pdf->SetMargins(PDF_MARGIN_LEFT, 49, PDF_MARGIN_RIGHT);
$pdf->SetMargins(PDF_MARGIN_LEFT, 49, 10);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
//set some language-dependent strings
$pdf->setLanguageArray($l);
// ---------------------------------------------------------
$pdf->setJPEGQuality(75); // set JPEG quality
$pdf->SetFont('helvetica', '', 10); // set font
$pdf->AddPage(); // add a page
// get all the needed data from the tables
$sqlCombination = "
SELECT person.*, horse.*, 2010Combination.*
FROM FEIPerson AS person
INNER JOIN 2010Combination ON person.fei_id = 2010Combination.personFEIid
INNER JOIN FEIHorse horse ON horse.fei_id = 2010Combination.horseFEIid
ORDER BY person.competing_for_country, 2010Combination.compNumber ASC ";
$Result = mysql_query($sqlCombination);
if(!$Result) {
$html = 'There is een error opening table for listing Combinations; '.mysql_error();
$pdf->writeHTML($html, true, false, true, false, ' ');
}
$numberCombination = mysql_affected_rows();
if(!$result || ($numberCombination < 0)) { }
elseif($numberCombination > 0) {
for($i=0; $i<$numberCombination; $i++) {
$Row = mysql_fetch_assoc($Result);
$sqlCountry = "SELECT e_country FROM country WHERE ISO_A3 = '".$Row['competing_for_country']."'";
if (!(@ $resultCountry = mysql_query($sqlCountry))) {
$html = 'There was an error running your query: '.mysql_error();
$pdf->writeHTML($html, true, false, true, false, ' ');
}
$country_name = mysql_result($resultCountry, 0, e_country);
$pdf->SetFont('arialunicid0', '', 9);
$pdf->SetFont('helvetica', '', 9);
if($riderNF != $Row['competing_for_country']) {
$html = '<br /><br /><img border="0" src="images/Flags/'.$country_name.'.png" height="20"> <font size="+4"><b>'.$country_name.'</b></font> ('.$Row['competing_for_country'].')<br />
<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<th width="18"> </th>
<th width="175">Rider</th>
<!--th width="210">Horse</th--><!-- In 2015 vervallen -->
<th width="50">Bad Boekelo</th>
<th width="50">Caravan</th>
<th width="175">Groom</th>
</tr>
</table>';
$pdf->writeHTMLCell(0, 0, '', '', $html, 'B', 1, 0, true, 'L', false);
}
$html = '<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td width="25"> '.$Row[compNumber].'</td>
<td width="175"> '.$Row['first_name'].' '.ucwords(strtolower($Row['family_name'])).'</td>
<!--td width="210"> '.$Row['complete_name'].'</td--><!-- In 2015 vervallen -->';
if($Row['stayHorseBox'] == 'Yes')
{ $html = $html.'<td width="50" > Lorry </td>'; }
else if($Row['appartmentBB'] == 'No')
{ $html = $html.'<td width="50" > No </td>'; }
else if($Row['appartmentNumber'] == 0)
{ $html = $html.'<td width="50" border="1"></td>'; }
else
{ $html = $html.'<td width="50" >'.$Row['appartmentNumber'].'</td>'; }
if($Row['accomGroom'] == 'No')
{ $html = $html.'<td width="50" > No </td>'; }
else
if($Row['caravanNumber'] == 0)
{ $html = $html.'<td width="50" border="1"></td>'; }
else
{ $html = $html.'<td width="50"> '.$Row['caravanNumber'].' </td>'; }
if($Row['genderGroom'] == 'Female') {$genderGroom = '(F)';} else { $genderGroom = '(M)'; }
$html = $html.'<td width="175"> '.$Row['nameGroom'].' '.$genderGroom.' </td>
</tr>
</table>';
$pdf->writeHTML($html, false, false, true, false, ' ');
// Add newpage if next country
/*
if($riderNF == $Row['competing_for_country']
{ }
else
{ $pdf->AddPage(); }
*/
$riderNF = $Row['competing_for_country'];
}
} else {
$html = 'No records found.';
$pdf->writeHTML($html, true, false, true, false, ' ');
}
//Close and output PDF document
$pdf->Output('AccomodationOverview.pdf', 'I');
?>
De if/else zit aan het eind.
De vraag is waarom laten deze regels het script niet uitvoeren en/of moet de addPage ergens anders staan?
Edit:
php tags verwijdert
php tags verwijdert
Gewijzigd op 24/09/2015 17:47:54 door Harry H Arends
Kan je de code tussen code-tags plaatsen? Dat maakt het beter leesbaarder, want de PHP-tag is bedoeld voor linken naar PHP-functies.
Als ik een bericht maak kan ik geen kodetags kiezen.
Zonder streepjes dan.
Code (php)
Gewijzigd op 26/09/2015 11:35:29 door Johan K
Harry H Arends op 24/09/2015 17:46:37:
Wil ik graag doen maar welke tags zijn dat dan.
Als ik een bericht maak kan ik geen kodetags kiezen.
Als ik een bericht maak kan ik geen kodetags kiezen.
Zie ook de 'veel gestelde vragen'
Nu loop ik tegen een tweede probleem aan met de if constructie.
Zit er een m,aximum aan het aantal else/if>
Code (php)
Als ik de tweede elseif erbij doe werkt het script niet meer.
Enig idee?
Harry H Arends op 25/09/2015 13:13:18:
Als ik de tweede elseif erbij doe werkt het script niet meer.
Enig idee?
Enig idee?
Error-reporting aan staan?
error_reporting(E_ALL ^E_NOTICE); staat boven in het script
Harry H Arends op 26/09/2015 12:36:23:
error_reporting(E_ALL ^E_NOTICE); staat boven in het script
Als dat zo was, had je ook een error gekregen op die syntax error.
Misschien moet je "error reporting" eens aanzetten nadat je alles include.
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
<?php
include("datacon.php");
include("include/functions.php");
include("tcPDF_inc.php");
// tcPDF scripts used once
require_once('../tcpdf/config/lang/eng.php');
require_once('../tcpdf/tcpdf.php');
error_reporting(E_ALL & ~E_DEPRECATED);
ini_set('display_errors', 1);
?>
include("datacon.php");
include("include/functions.php");
include("tcPDF_inc.php");
// tcPDF scripts used once
require_once('../tcpdf/config/lang/eng.php');
require_once('../tcpdf/tcpdf.php');
error_reporting(E_ALL & ~E_DEPRECATED);
ini_set('display_errors', 1);
?>
Het grootste probleem met dit script is jouw accolades, gebruik deze consistent en niet de ene keer wel en de andere keer niet, dan nog een andere keer op een andere regel en op die ook weer sluiten.
Je mag namelijk met PHP ook geen accolades gebruiken in je if else statement, maar deze moet consistent zijn over de gehele if else.
Gewijzigd op 27/09/2015 12:14:08 door Johan K