我收到以下错误">分析错误:语法错误,第46行/Applications/XAMPP/examplepfiles/htdocs/website-proiecte.dataserv.ro/includes/pintAnexa2.inc.php中出现意外的"while"(T_while(,应为"(">";。
无法确定错误在哪里。这也是代码:
<?php
require_once ('../vendor/autoload.php');
require_once ('dbh.inc.php');
$mpdf = new MpdfMpdf(['tempDir' => __DIR__ . '../tmp']);
if(isset($_GET['report-id']))
{
$id = $_GET['report-id'];
$sql = "SELECT * FROM planning
inner join classes on classes.classesClass = planning.planningClass
WHERE planningId = '$id'
";
$result = mysqli_query($conn, $sql);
// raport anexa 2
$mpdf->AddPage('P');
$mpdf->WriteHTML('
<img src="../img/ue-logo.jpg" height="60" width="auto" />
<img style="padding-left: 32%;" src="../img/gr-logo.jpg" height="60" width="auto" />
<img style="padding-left: 32%;" src="../img/is-logo.jpg" height="60" width="auto" />
<br /><br />
<p style="text-align: right; padding-right: 5%;"><strong>ANEXA 2</strong></p>
<br />
<h3 style="text-align: center;">GRAFIC INSTRUIRE PRACTICĂ</h3>
<br /><br /><br /><br /><br />
<table style="border:1px solid black; width:100%;">
<tr>
<th>Clasa</th>
<th>Saptamana</th>
<th>Data Start</th>
<th>Data Finalizare</th>
<th>Ora incepere</th>
<th>Ora terminare</th>
</tr>
<tr>'
while($fetch = mysqli_fetch_array($result)) {'
<td>' . $fetch['planningClass'] . '</td>
<td>' . $fetch['planningWeek'] . '</td>
<td>' . $fetch['planningDateStart'] .'</td>
<td>' . $fetch['planningDateEnd'] . '</td>
<td>' . $fetch['planningHourStart'] .'</td>
<td>' . $fetch['planningHourEnd'] . '</td>
</tr>
</table> ' } '
');
}
$mpdf->Output();
不能将while循环放入字符串中。
将它放在外部并将结果分配给字符串,然后将其连接到WriteHTML的内部。看看这段代码,这应该对你有用。
require_once ('../vendor/autoload.php');
require_once ('dbh.inc.php');
$mpdf = new MpdfMpdf(['tempDir' => __DIR__ . '../tmp']);
if(isset($_GET['report-id']))
{
$id = $_GET['report-id'];
$sql = "SELECT * FROM planning
inner join classes on classes.classesClass = planning.planningClass
WHERE planningId = '$id'
";
$result = mysqli_query($conn, $sql);
// raport anexa 2
$row='';
while($fetch = mysqli_fetch_array($result)) {
$row.='
<tr>
<td>' . $fetch['planningClass'] . '</td>
<td>' . $fetch['planningWeek'] . '</td>
<td>' . $fetch['planningDateStart'] .'</td>
<td>' . $fetch['planningDateEnd'] . '</td>
<td>' . $fetch['planningHourStart'] .'</td>
<td>' . $fetch['planningHourEnd'] . '</td>
</tr>';
}
$mpdf->AddPage('P');
$mpdf->WriteHTML('
<img src="../img/ue-logo.jpg" height="60" width="auto" />
<img style="padding-left: 32%;" src="../img/gr-logo.jpg" height="60" width="auto" />
<img style="padding-left: 32%;" src="../img/is-logo.jpg" height="60" width="auto" />
<br /><br />
<p style="text-align: right; padding-right: 5%;"><strong>ANEXA 2</strong></p>
<br />
<h3 style="text-align: center;">GRAFIC INSTRUIRE PRACTICĂ</h3>
<br /><br /><br /><br /><br />
<table style="border:1px solid black; width:100%;">
<tr>
<th>Clasa</th>
<th>Saptamana</th>
<th>Data Start</th>
<th>Data Finalizare</th>
<th>Ora incepere</th>
<th>Ora terminare</th>
</tr>
'.$row.'
</table>
');
}
$mpdf->Output();