0

Have been struggling with making this work. Not sure where I'm going wrong.

main page: 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();
?>

Directly under the table within the while() I would like it to display the patients for that result. I have tried doing an include of a page, but it just shows only the top row of the main page (instead of maybe 5 or 6 rows based on query results). And it shows the number 1 under it.

The code on the pkg_patient.php is:

<?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();
?>
  • 1
    You should explain your problem more clearly. Creating a small code example that reproduces your problem more concisely so that it is easy to digest for someone trying to help. Doing this might also help you solve the problem yourself. I'm not used to PHP, but are you sure the syntax to include another php file really is `echo include the/url.php`? See this question: http://stackoverflow.com/questions/921479/include-whole-content-of-a-file-and-echo-it – Joakim Jan 22 '15 at 18:07

2 Answers2

0

You don't need to re-run the query in pkg_patient.php, all the variables from pkg_list_30d.php are accessible from pkg_patient.php once you've included it...

Noy
  • 1,258
  • 2
  • 11
  • 28
  • but they're not, unless I'm not entirely understanding. the query on both pages is different. the child page (pkg_patient.php) is trying to get & display data based on the query for pkg_list_30d.php –  Jan 22 '15 at 18:22
0

In pkg_list_30d.php on line 68 you use echo include 'pkg_patient.php';

Instead you should echo the data you're wanting to display on pkg_patient.php and include it using include pkg_patient.php on pkg_list_30d.php

  • this is what i'm doing, pkg_patient is the page i'm trying to include. within this page i have already echo'd the results that i want. so on the main page, pkg_list_30d.php if the pkgID for the first row is 1, it should include the results on pkg_patient.php, which is set to be included under that "row", prior to the next row. –  Jan 22 '15 at 18:24
  • But did you try removing the echo from in front of the include statement? Trying to echo the statement doesn't seem to be in line with what you're trying to accomplish. – Keith Seal Jan 22 '15 at 18:39
  • sorry, yes I did try that. when I do it, I get the LIMIT 5 rows, but no "data" populates from the include page. when I test a query in Toad simulating what should be the pkgID for the pkg_patient.php, I get results as I would expect. but i'm not sure why I can't get this information to show up via the .php pages. maybe it's my noob-iness –  Jan 22 '15 at 20:10