Jump to content

[SOLVED] where to echo the $row[variable]?


jeff5656

Recommended Posts

How do I echo something from a $row[] BEFORE the while loop?  If I do it in the while loop it disoplays for each record.  But my $row['patient'] is always the same for all the rows.

I want to make it a heading before the while loop like:

echo "Billing data for patient: " . $row['patient'];

 

But then it is blank!  How do I do that for this code:

 

 $result = mysql_query ($sql) or die ("Invalid query: " . mysql_error ());
   echo "<table>";
$i=0;
    while ($row = mysql_fetch_assoc ($result)) { 
      if ($row['billing_date'] != $oldDate) {
           if ($i != 0) {
               echo implode(", ", $diagnos) . '</td></tr>';
              $i++;
           }
           echo '<tr>';
           echo "<td> pt_id: " . $row['pt_id'] ."</td>";
           echo "<td>" . $row['patient'] . " " ."</td>";
	   echo "<td>" . $row['billing_lvl'] . " " ."</td>";
           echo "<td>" . $row['billing_date'] ."</td>";
           echo "<td>";
           $diagnos = array();
      }
      $diagnos[] = $row['diagnosis'];
      $oldDate = $row['billing_date'];
      }
echo implode(", ", $diagnos) . "</td></tr></table>";

Link to comment
https://forums.phpfreaks.com/topic/136560-solved-where-to-echo-the-rowvariable/
Share on other sites

<?php
$result = mysql_query ($sql) or die ("Invalid query: " . mysql_error ());
$row = mysql_fetch_assoc ($result);
echo "Patient: $row['patient']";
   echo "<table>";
$i=0;
   do{
      if ($row['billing_date'] != $oldDate) {
           if ($i != 0) {
               echo implode(", ", $diagnos) . '</td></tr>';
              $i++;
           }
           echo '<tr>';
           echo "<td> pt_id: " . $row['pt_id'] ."</td>";
           echo "<td>" . $row['patient'] . " " ."</td>";
         echo "<td>" . $row['billing_lvl'] . " " ."</td>";
           echo "<td>" . $row['billing_date'] ."</td>";
           echo "<td>";
           $diagnos = array();
      }
      $diagnos[] = $row['diagnosis'];
      $oldDate = $row['billing_date'];
      } while ($row = mysql_fetch_assoc ($result));
echo implode(", ", $diagnos) . "</td></tr></table>";
?>

assoc first, then move while to end of loop...

 

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.