troubleshooting Question

looping through arrays issue

Avatar of nwalker78
nwalker78 asked on
PHPMySQL ServerWeb Development
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

  $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;
	$query = sprintf("SELECT 
							######.FLD_EMPID = '%s'
							######.FLD_ROTRD > '%s'
							######.FLD_ROTRD < '%s'",  
	$result = mysql_query($query);
	$result = db_result_to_array($result);
	return $result;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<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">
      <td colspan=7 style="height:4px; "></td>
    <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 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>

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

    <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>

      <td height="4" colspan="7" class="brdr-ts" style="height:2px; font-size: 2px;">&nbsp;</td>
  <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>


Open in new window


Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
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