jeff5656 Posted December 11, 2008 Share Posted December 11, 2008 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 More sharing options...
Brian W Posted December 11, 2008 Share Posted December 11, 2008 <?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... Link to comment https://forums.phpfreaks.com/topic/136560-solved-where-to-echo-the-rowvariable/#findComment-712840 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.