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

PHP包含页面,该页面根据第1页的值显示信息,php,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_

我一直在努力使这项工作成功。我不知道我会错在哪里

主页: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_list_30d.php
中的所有变量都可以从
pkg_patient.php
中访问,只要您将其包含在第68行的pkg_list_30d.php中……

echo包括“pkg_patient.php”


相反,您应该回显希望在pkg_patient.php上显示的数据,并使用pkg_list_30d.php上的
include pkg_patient.php
将其包含在内。您应该更清楚地解释您的问题。创建一个小的代码示例,以更简洁地再现您的问题,从而使试图帮助您的人易于理解。这样做也可以帮助你自己解决问题。我不习惯PHP,但您确定包含另一个PHP文件的语法真的是
echo include/url.PHP
?看这个问题:但他们不是,除非我不完全理解。两个页面上的查询都不同。子页面(pkg_patient.php)正在尝试根据pkg_list_30d的查询获取和显示数据。php这就是我正在做的,pkg_patient就是我试图包含的页面。在这个页面中,我已经重复了我想要的结果。因此,在主页上,pkg_list_30d.php如果第一行的pkgID为1,它应该在下一行之前包含pkg_patient.php上的结果,该结果设置为包含在该“行”下。但是您是否尝试从include语句前面删除回显?试图附和这句话似乎与你想要实现的目标不符。对不起,是的,我试过了。当我这样做时,我得到了5行的限制,但是没有从include页面填充“数据”。当我在Toad中测试一个查询,模拟pkg_patient.php的pkgID应该是什么时,我得到了预期的结果。但是我不确定为什么我不能通过.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();
?>