PHP 包含页面,它根据页面 1 的值显示信息


PHP Include Page which shows information based on value of Page 1

一直在努力使这项工作。不知道我哪里出错了。

主页: pkg_list_30d.php

<?php
$conn = new mysqli('host', 'user', 'pwd',    'db');
// check connection
if (mysqli_connect_errno()) {
exit('Connect failed: '. mysqli_connect_error());
}
// check connection
if (mysqli_connect_errno()) {
exit('Connect failed: '. mysqli_connect_error());
}
// SELECT sql query
$sql = "SELECT pkg.*, i.isotope AS pkgisotope
FROM tbl_packagereceipt pkg
INNER JOIN tbl_isotopes i
on
pkg.isotope = i.isoID
GROUP BY pkg.pkgID
ORDER BY `datereceived` DESC
LIMIT 5"; 
// perform the query and store the result
$result = $conn->query($sql);
// if the $result contains at least one row
if ($result->num_rows > 0) {
// output data of each row from $result
echo '
<table width="568" border="0" cellspacing="1" cellpadding="1">
<tr>
<td width="80" >&nbsp;</td>
<td width="110">&nbsp;</td>
<td width="108">&nbsp;</td>
<td width="150">&nbsp;</td>
<td width="120" >&nbsp;</td>
</tr>
<tr>
 <td>&nbsp;</td>
 <td><strong>Date</strong></td>
 <td><strong>Package #</strong></td>
 <td><strong>Isotope</strong></td>
 <td>&nbsp;</td>
</tr>
</table>';
$c = false;
while($row = $result->fetch_assoc())   
{ 
 echo '<table width="568" border="0" cellspacing="1" cellpadding="1">
 <tr style="background:',(($c=!$c)? '#eee' : '#ddd' ),'">
 <td width="80">&nbsp;</td>
 <td width="110">'.date('d-M-Y', strtotime($row['datereceived'])).'</td>
 <td width="108">'.$row['pkgnumber'].'</td>
 <td width="150">'.$row['pkgisotope'].'</td>
 <td width="120">' . '<a class="gegevens2" 
 href="../patientinjection/record_inj_form.php?id=' . $row['pkgID'] . '"> ' .      
 "Add Patient". '</a>' . '</td>
</tr>
</table>
<br />';
echo include 'pkg_patient.php';
}
}
else {
echo 'All packages returned.';
}
$conn->close();
?>

在 while() 内的表格正下方,我希望它显示患者以获得该结果。我尝试对页面进行包含,但它只显示主页的第一行(而不是基于查询结果的 5 或 6 行)。它下面显示了数字 1。

pkg_patient.php上的代码是:

<?php
$conn = new mysqli(removed);
// check connection
if (mysqli_connect_errno()) {
  exit('Connect failed: '. mysqli_connect_error());
}
// check connection
if (mysqli_connect_errno()) {
exit('Connect failed: '. mysqli_connect_error());
}
// SELECT sql query
$pkgID = (int)$_GET[$id];
$sql = "SELECT pdi.*, radp.radiopharmaceutical AS radp, pkp.initials
FROM tbl_patientdoseinformation pdi
INNER JOIN tbl_isotopes i
ON
pdi.isotope = i.isoID
INNER JOIN tbl_radpharmaceuticals radp 
ON pdi.isotope = radp.isotopeID 
INNER JOIN tbl_packagepersonnel pkp
ON pdi.adminby = pkp.pkgpersonnelID
WHERE pdi.pkgnumberID='" . $pkgID . "'
GROUP BY pdi.patientdoseID
ORDER BY `datetimestated` DESC"; 
// perform the query and store the result
$result = $conn->query($sql);
// if the $result contains at least one row
if ($result->num_rows > 0) {
// output data of each row from $result
echo '<table width="1103" border="0" cellspacing="1" cellpadding="1">
<tr>
<td colspan="9"></td>
</tr>
<tr>
<td width="80" >&nbsp;</td>
<td width="110">&nbsp;</td>
<td width="108">&nbsp;</td>
<td width="161">&nbsp;</td>
<td width="84">&nbsp;</td>
<td width="151">&nbsp;</td>
<td width="83">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><strong>Date</strong></td>
<td><strong>Case No.</strong></td>
<td><strong>Radiopharmaceutical</strong></td>
<td><strong><div align="center">Dose</div></strong></td>
<td><strong><div align="right">State Date/Time</div></strong></td>
<td><strong><div align="right">Initials</div></strong></td>
</tr>
</table>
<br />';
$c = false;
while($row = $result->fetch_assoc())   
{ 
echo '<table width="1103" border="0" cellspacing="1" cellpadding="1">
 <tr style="background:',(($c=!$c)? '#eee' : '#ddd' ),'">
<td width="80">' . '<a class="gegevens" href="edit_inj_form.php?id=' . 
$row['patientdoseID'] . '"> ' . "Edit". '</a>' . '</td>
<td width="117">'.date('d-M-Y', strtotime($row['datetimestated'])).'</td>
<td width="108">'.$row['patientID'].'</td>
<td width="161">'.$row['radp'].'</td>
<td width="84"><div align="right">'.$row['dose'].' mCi</div></td>
<td width="180"><div align="right">'.date('d-M-Y H:i', 
strtotime($row['datetimestated'])).'</div></td>
<td width="83"><div align="right">'.$row['initials'].'</div></td>
</tr>
</table>';
}
}
else {
echo '&nbsp;';
}
$conn->close();
?>

您无需在 pkg_patient.php 中重新运行查询,一旦包含它,就可以从pkg_patient.php访问pkg_list_30d.php中的所有变量......

在第 68 行的pkg_list_30d.php中,您使用 echo include 'pkg_patient.php';

相反,您应该回显要在pkg_patient.php上显示的数据,并使用include pkg_patient.php将其包含在pkg_list_30d.php