Jump to content

[SOLVED] Simple Question


scarface83

Recommended Posts

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

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>


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>

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.

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();




?>

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.