Jump to content

[SOLVED] strange loop results


simon551

Recommended Posts

I'm racking my brain on this all day. Can you see a problem with my code?

Basically, I'm echoing out some info about each account. And then echoing out details related to that account, so I'm creating two loops to run through it all. This is an intranet admin stuff site. There are a couple problems that are happening: the data doesn't match up to the record when it echoes out (something wrong with the loop) and the inside loop table's width starts out very wide (2-3x times the screen width) and then gradually through each loop gets smaller until it's too small and stops showing up at all.

I really appreciate it if you can offer me a nugget...

</head>

<body>
<div id="main">
<table width="375">
<?php 
//start first loop: count employees 	
do {
$cellType=$row_cells_countEmp['cellType'];
echo $cellType;
?>
<tr>
<td><strong><?php echo $row_cells_countEmp['employee'] ?></strong></td>
</tr>
<tr>
<td>Plan Type: <?php echo $row_cells_countEmp['cellType'] ?></td>
</tr>
<tr>
<td>Stipend Amount: <?php echo $row_cells_countEmp['stipendAmt'] ?></td>
</tr>
<tr>
<td><a href="cell_new.php">edit</a></td>
</tr>
<tr>
<td>
<table width="250" align="center">
  <tr class="tableheader">
    <th width="200">Account</th>
    <th width="50">Amount </th>
  </tr>

<?php
$cellPlanId=$row_cells_countEmp['cellPlanId'];
$query_cell1 = "SELECT contract_cellDets.cellDetId, contract_cellDets.contractID,   contract_cellDets.perc, contract_cellDets.cAmount,  CONCAT(tblclients.clientName,' - ',tbldivisions.division) AS contract FROM contract_cellDets INNER JOIN cell_plans ON contract_cellDets.cellPlanId = cell_plans.cellPlanId INNER JOIN contracts ON contract_cellDets.contractId=contracts.contractId INNER JOIN tblclients ON contracts.clientId=tblclients.clientId INNER JOIN tbldivisions on contracts.divisionID=tbldivisions.DivID WHERE contract_cellDets.cellPlanId =$cellPlanId ".$hrAdminCriteria.$planTypeCriteria;
$cell1 = mysql_query($query_cell1, $conn_org) or die($query_cell1.mysql_error());
$row_cell1 = mysql_fetch_assoc($cell1);
$tot=0;
$totPerc=0;
//start second loop inside first. echo out details from query
do  {	
?>
    <tr class="d0" >
      <td><?php echo $row_cell1['contract']; ?></td>
      <td><?php
  if ($cellType=="personal plan")
  {
		$amount=(($row_cell1['perc'])*100).'%';
  }
	if ($cellType=="company plan")
			{
				$amount= DoFormatCurrency($row_cell1['cAmount'], 2, '.', ',', '$'); 
			}	

	echo $amount;
	?>
     </td>
  </tr>
<?php 
	$tot+=$row_cell1['cAmount'];
	$totPerc+=$row_cell1['perc'];
//end inside loop
} while ($row_cell1 = mysql_fetch_assoc($cell1));
?>
  <tr class="d2">
    <td><strong>Total <?php echo $emp;?></strong></td>
    <td><strong>
<?php
if ($cellType=="personal plan") 
	{
		$percentage=(($totPerc)*100);
		 echo $percentage.'%'; 
	}	 
		if ($cellType=="company plan")
				{
				echo  DoFormatCurrency($tot, 2, '.', ',', '$'); 
			}
?></strong>
     </td>
  </tr>
<?php
//end first loop
} while ($row_cells_countEmp = mysql_fetch_assoc($cells_countEmp)); ?>
</table>
</td>
</tr>
</table>
</div>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/109660-solved-strange-loop-results/
Share on other sites

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.