jeff5656 Posted March 24, 2008 Share Posted March 24, 2008 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 More sharing options...
Barand Posted March 24, 2008 Share Posted March 24, 2008 after query pseudo code read first row, get the date do { /// output record } while fetch next row Link to comment https://forums.phpfreaks.com/topic/97682-echo-a-variable-before-the-while-loops/#findComment-499828 Share on other sites More sharing options...
jeff5656 Posted March 24, 2008 Author Share Posted March 24, 2008 Do I use something like extract (... actually, I am not sure how to select the first row after the query. Will this also screw up the while loop? Link to comment https://forums.phpfreaks.com/topic/97682-echo-a-variable-before-the-while-loops/#findComment-499841 Share on other sites More sharing options...
Barand Posted March 24, 2008 Share Posted March 24, 2008 I am not sure how to select the first row after the query. $row = mysql_fetch_assoc ($results) Will this also screw up the while loop? Yes, which is why I used do ... while() instead. Link to comment https://forums.phpfreaks.com/topic/97682-echo-a-variable-before-the-while-loops/#findComment-499849 Share on other sites More sharing options...
soycharliente Posted March 24, 2008 Share Posted March 24, 2008 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? Link to comment https://forums.phpfreaks.com/topic/97682-echo-a-variable-before-the-while-loops/#findComment-499856 Share on other sites More sharing options...
jeff5656 Posted March 24, 2008 Author Share Posted March 24, 2008 $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! Link to comment https://forums.phpfreaks.com/topic/97682-echo-a-variable-before-the-while-loops/#findComment-499859 Share on other sites More sharing options...
wildteen88 Posted March 24, 2008 Share Posted March 24, 2008 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); Link to comment https://forums.phpfreaks.com/topic/97682-echo-a-variable-before-the-while-loops/#findComment-499863 Share on other sites More sharing options...
jeff5656 Posted March 24, 2008 Author Share Posted March 24, 2008 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']; Link to comment https://forums.phpfreaks.com/topic/97682-echo-a-variable-before-the-while-loops/#findComment-499871 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.