troubleshooting Question

looping through arrays issue

Avatar of nwalker78
nwalker78 asked on
Web DevelopmentPHPMySQL Server
8 Comments1 Solution333 ViewsLast Modified:
hi i am trying to format data retrieved from a MySQL table, however i cant seem to get it looping properly. the desired layout needed is something like fig-1Example fig-1 but ive tried sev4ral diffrent looping layouts fig-2 gives leas5t probs. Example fig-2
the code for fig 2 is

<?php
  $bttot1= 0;
  $lttot1= 0;
  $tttot1= 0;
  $nttot1= 0;
  $ettot1= 0;
$mode = array();
$rota = 0;
  
$rotadetails = rdetail($rota);


   
   
   
  function dbConnection()
  {
  
	$connection = mysql_connect('localhost', '########', '########') or die ($errorlist['1'] . mysql_error());
	
	mysql_select_db('######', $connection) or die ($errorlist['2'] . mysql_error());
	
	return $connection;
  }
  /**
  * Turns MYSQL resource into array
  * @param resource $result
  * @return array: $res_array
  */
  function db_result_to_array($result)
  {
	$res_array = array();
	  for ($count=0;  $row = mysql_fetch_array($result); $count++)
	  {
		$res_array[$count] = $row;
	  }
	return $res_array;
  }
  
  
 function rdetail($id)
  {
	$rsdate = 1369612800;
	$sectoday	= 86400;
	$days 	= $sectoday*13;
	dbConnection();
	$query = sprintf("SELECT 
							* 
						FROM 
							######
						WHERE 
							######.FLD_EMPID = '%s'
						AND
							######.FLD_ROTRD > '%s'
						AND
							######.FLD_ROTRD < '%s'",  
							mysql_real_escape_string($id),
							($rsdate-1),
							($rsdate+$days+1));
	$result = mysql_query($query);
	$result = db_result_to_array($result);
	return $result;
  }
	   
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="includes/css/test.css" rel="stylesheet" type="text/css" /></head>

<table width=633 border=0 align="center" cellpadding=0 cellspacing=0 class="derder">
    <tr>
      <td colspan=7 style="height:4px; "></td>
    </tr>
    <tr align="center">
      <td width="70" colspan=1 rowspan="2" class="brdr-bs">Week 1</td>
      <td width="80" colspan=1 bgcolor="#DBE5F1" class="brdr-ts brdr-ls">Breakfast</td>
      <td width="80" colspan=1 bgcolor="#DBE5F1" class="brdr-ts">Lunch</td>
      <td width="80" colspan=1 bgcolor="#DBE5F1" class="brdr-ts">Dinner</td>
      <td width="80" colspan=1 bgcolor="#DBE5F1" class="brdr-ts">Bed</td>
      <td width="120" colspan=2 bgcolor="#DBE5F1" class="brdr-ts brdr-rs">Extra Time</td>
    </tr>
  <tr align="center">
    <td width="80" colspan=1 bgcolor="#DBE5F1" class="brdr-bs brdr-ls">08:00-09:00</td>
    <td width="80" colspan=1 bgcolor="#DBE5F1" class="brdr-bs">13:30-14:30</td>
    <td width="80" colspan=1 bgcolor="#DBE5F1" class="brdr-bs">17:00-18:00</td>
    <td width="80" colspan=1 bgcolor="#DBE5F1" class="brdr-bs">22:00-23:00</td>
    <td width="60" colspan=1 bgcolor="#DBE5F1" class="brdr-bs">Duration</td>
    <td width="60" colspan=1 bgcolor="#DBE5F1" class="brdr-bs brdr-rs ">Start</td>
  </tr>
<?php


foreach   ($rotadetails as $rotadetail)
{
	
$bttot1 = $bttot1 + $rotadetail['FLD_ROTH1']; // Running total for week 1 Breakfast Calls
$lttot1 = $lttot1 + $rotadetail['FLD_ROTH2']; // Running total for week 1 Lunch Calls
$tttot1 = $tttot1 + $rotadetail['FLD_ROTH3']; // Running total for week 1 Dinner Calls
$nttot1 = $nttot1 + $rotadetail['FLD_ROTH4']; // Running total for week 1 Night Calls
$ettot1 = $ettot1 + $rotadetail['FLD_ROTH5T']; // Running total for week 1 Extra Calls

?>
  <tr>
    <td colspan=1 class="brdr-lrs"><?php echo date("l",$rotadetail['FLD_ROTRD']);?></td>
      <td colspan=1 class="fmt-text"><?php echo $rotadetail['FLD_ROTH1']; ?></td>
      <td colspan=1 class="fmt-text"><?php echo $rotadetail['FLD_ROTH2']; ?></td>
      <td colspan=1 class="fmt-text"><?php echo $rotadetail['FLD_ROTH3']; ?></td>
      <td colspan=1 bgcolor="#DBE5F1" class="fmt-text brdr-lrs"><?php echo $rotadetail['FLD_ROTH4']; ?></td>
      <td colspan=1 class="fmt-text"><?php echo $rotadetail['FLD_ROTH5T']; ?></td>
      <td class="brdr-rs">&nbsp;</td>
  </tr>

    <?php 
  }
?>
    <tr>
      <td height="4" colspan="7" class="brdr-ts" style="height:2px; font-size: 2px;">&nbsp;</td>
  </tr>
  <tr class="fmt-text">
      <td colspan=1 class="fmt-texthdr">TOTAL</td>
      <td colspan=1 class="brdr-bs brdr-ts brdr-ls"><?php echo $bttot1; ?></td>
      <td colspan=1 class="brdr-bs brdr-ts"><?php echo $lttot1; ?></td>
      <td colspan=1 class="brdr-bs brdr-ts"><?php echo $tttot1; ?></td>
      <td colspan=1 bgcolor="#DBE5F1" class="brdr-bs brdr-ts brdr-lrs"><?php echo $nttot1; ?></td>
      <td colspan=1 class="fmt-text brdr-rs brdr-bs brdr-ts"><?php echo $ettot1; ?></td>
      <td colspan=1 class="fmt-text brdr-rs brdr-bs brdr-ts"></td>
    </tr>  
</table>

</body>
</html>
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 8 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros