scarface83 Posted March 20, 2007 Share Posted March 20, 2007 Hi, the the table this query relates to holds 8 records but my code is only displaying one , how do i get it to print all the records into the table ? thanks <?php session_start() ; require('db_connect.inc'); $query = ("SELECT abs_value, ID, notes, datestamp FROM absence_mgt WHERE ID ='$vtc_login' AND abs_value='1' ORDER BY datestamp") or die (mysql_error); $run= mysql_query($query); while($late_qry = mysql_fetch_array($run)){ $notes = $late_qry['notes']; $datestamp = $late_qry['datestamp']; } ?> <table width="200" border="0"> <tr> <td>Lates</td> <td><?php echo $notes ; ?></td> <td><?php echo $datestamp ; ?></td> </tr> </table> Link to comment https://forums.phpfreaks.com/topic/43453-solved-simple-question/ Share on other sites More sharing options...
pocobueno1388 Posted March 20, 2007 Share Posted March 20, 2007 You have to print the variables out INSIDE the while loop. <?php session_start() ; require('db_connect.inc'); echo ' <table width="200" border="0"> <tr> <td>Lates</td>'; $query = ("SELECT abs_value, ID, notes, datestamp FROM absence_mgt WHERE ID ='$vtc_login' AND abs_value='1' ORDER BY datestamp") or die (mysql_error); $run= mysql_query($query); while ($late_qry = mysql_fetch_array($run)){ $notes = $late_qry['notes']; $datestamp = $late_qry['datestamp']; echo "<td>$notes</td>"; echo "<td>$datestamp</td>; echo '</tr>'; } ?> </table> Link to comment https://forums.phpfreaks.com/topic/43453-solved-simple-question/#findComment-211030 Share on other sites More sharing options...
JasonLewis Posted March 20, 2007 Share Posted March 20, 2007 pocobueno1388, your code has a little error in it. lol.. here it is again, fixed up: <?php session_start() ; require('db_connect.inc'); echo ' <table width="200" border="0"> <tr> <td>Lates</td>'; $query = ("SELECT abs_value, ID, notes, datestamp FROM absence_mgt WHERE ID ='$vtc_login' AND abs_value='1' ORDER BY datestamp") or die (mysql_error); $run= mysql_query($query); while ($late_qry = mysql_fetch_array($run)){ $notes = $late_qry['notes']; $datestamp = $late_qry['datestamp']; echo "<td>$notes</td>"; echo "<td>$datestamp</td>"; //you missed a " here echo "</tr>"; } ?> </table> Link to comment https://forums.phpfreaks.com/topic/43453-solved-simple-question/#findComment-211036 Share on other sites More sharing options...
scarface83 Posted March 20, 2007 Author Share Posted March 20, 2007 thanks for the help everyone , is there another way where i have the table then just echo the variables im sure i have seen it before ? Link to comment https://forums.phpfreaks.com/topic/43453-solved-simple-question/#findComment-211038 Share on other sites More sharing options...
JasonLewis Posted March 20, 2007 Share Posted March 20, 2007 there is some other ways, but why not just do it that way, its a lot simplier and easiier to code. Link to comment https://forums.phpfreaks.com/topic/43453-solved-simple-question/#findComment-211041 Share on other sites More sharing options...
scarface83 Posted March 20, 2007 Author Share Posted March 20, 2007 that way is perfect for now but when the script becomes more complicated im going to need a more robust way of printing the data thanks Link to comment https://forums.phpfreaks.com/topic/43453-solved-simple-question/#findComment-211044 Share on other sites More sharing options...
JasonLewis Posted March 20, 2007 Share Posted March 20, 2007 here is another way, which i dont think is as good as the one that is up there. <?php session_start() ; require('db_connect.inc'); $query = "SELECT abs_value, ID, notes, datestamp FROM absence_mgt WHERE ID ='$vtc_login' AND abs_value='1' ORDER BY datestamp"; $run = mysql_query($query) or die("Error: ".mysql_error()); $table_data = ""; while($late_qry = mysql_fetch_array($run)){ $notes = $late_qry['notes']; $datestamp = $late_qry['datestamp']; $table_data .= "<tr><td>{$notes}</td><td>{$datestamp}</td></tr> } ?> <table width="200" border="0"> <?php echo $table_data; ?> </table> i prefer the other method though. Link to comment https://forums.phpfreaks.com/topic/43453-solved-simple-question/#findComment-211048 Share on other sites More sharing options...
scarface83 Posted March 20, 2007 Author Share Posted March 20, 2007 yeah i see what you mean thanks , also do you now an easier way to do the following queries ? <?php require ('db_connect.inc'); $query ="SELECT abs_value, SUM(abs_value) FROM absence_mgt WHERE ID='$vtc_login' AND abs_value='1' GROUP BY abs_value "; //late $query2="SELECT abs_value, SUM(abs_value) FROM absence_mgt WHERE ID='$vtc_login' AND abs_value='2' GROUP BY abs_value "; //sick $query3="SELECT abs_value, SUM(abs_value) FROM absence_mgt WHERE ID='$vtc_login' AND abs_value='3' GROUP BY abs_value "; // sick half day $query4="SELECT abs_value, SUM(abs_value) FROM absence_mgt WHERE ID='$vtc_login' AND abs_value='4' GROUP BY abs_value "; //awol $run =mysql_query($query) or die(mysql_error()); $run2 =mysql_query($query2) or die(mysql_error()); $run3 =mysql_query($query3) or die(mysql_error()); $run4 =mysql_query($query4) or die(mysql_error()); $late_num =mysql_fetch_array($run); $sick_num =mysql_fetch_array($run2); $sickhf_num =mysql_fetch_array($run3); $awol_num =mysql_fetch_array($run4); mysql_close(); ?> Link to comment https://forums.phpfreaks.com/topic/43453-solved-simple-question/#findComment-211062 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.