Jump to content

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'];

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.