PHP包含显示基于第1页值的信息的页面

时间:2015-01-22 17:50:41

标签: php

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

主页: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();
?>

2 个答案:

答案 0 :(得分:0)

您不需要在pkg_patient.php中重新运行查询,pkg_list_30d.php中的所有变量都可以在pkg_patient.php包含后从{{1}}访问。

答案 1 :(得分:0)

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

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