Jump to content

echo a variable before the while loops


jeff5656

Recommended Posts

There is a field called conf_date that I want to echo before I display all of the records (see code below).  This field is the same for all records WHERE followup_stats = 'a'.

 

How do I echo this at the beginning of the page?

 

<?php

$query = "SELECT * ".
	"FROM xrayconf WHERE signoff_status = 'a' ".
	"ORDER BY patient_name";
$results = mysql_query ($query) or die (mysql_error());
$num_pts = mysql_num_rows ($results);

echo "<div align=center>";
echo "Cases for CXR Conference ";
echo $row['conf_date'];
echo "<br/>";
echo "<table width=\"80%\">";

while ($row = mysql_fetch_assoc ($results)) {
?>
<tr>
  <td>PATIENT: <?php echo $row['patient_name'];?>     
  <?php echo $row['mrn'];?> </td>
  </tr>
  <tr><td><?php echo $row['hx'];?></td></tr>
  <tr><td><strong>CXR's:</strong> <?php echo $row['show_xr'];?>   <strong>CT's:</strong> <?php echo $row['show_ct'];?></td></tr>
  <tr><td><strong>Path:</strong> <?php echo $row['show_path'];?></td></tr>
  <tr><td>Diagnosis: <?php echo $row['dx'];?></td></tr>
  <tr><td>Teaching point: <?php echo $row['teach'];?> </td>
  <tr><td>Additional comments<?php echo $row['comments'];?> </td></tr>
  
           </tr>
           <tr><td>--------------------------------------------------------------</td></tr>
      <?php
     }
     ?>
     
</table>

Link to comment
https://forums.phpfreaks.com/topic/97682-echo-a-variable-before-the-while-loops/
Share on other sites

$query = "SELECT * ".
	"FROM xrayconf WHERE signoff_status = 'a' ".
	"ORDER BY patient_name";
$results = mysql_query ($query) or die (mysql_error());
$num_pts = mysql_num_rows ($results);
$row = mysql_fetch_assoc ($results)

echo "<div align=center>";
echo "Cases for CXR Conference ";
do {
extract ($row);
echo $conf_date;

 

Can you help a bit more - where do I put the while and what do I say for that while?

 

I basically want to read conf_date from the first row and echo that, without interferring with the rest of the code.  How do I do that?  I guess I better read more about PHP before asking these questions because the answers assume I know alot more about code than I do!

Yes, which is why I used do ... while() instead.

What's the advantage of a do / while loop as opposed to just a regular while loop?

PHP will always execute the code in the do clause first regardless of the argument in the while statement.

 

eg:

$i = false;
do {
   echo 'While loop ran';
}
while($i == true);

Ok why does this not work:

$query = "SELECT * ".
	"FROM xrayconf WHERE signoff_status = 'a' ".
	"ORDER BY patient_name";
$results = mysql_query ($query) or die (mysql_error());
$num_pts = mysql_num_rows ($results);

$row = mysql_fetch_array($results) or die(mysql_error());
echo "<div align=center>";
echo "Cases for CXR Conference ";
echo $row['conf_date'];

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.