Hi all,

Can anyone help me ragarding my new project, im having a hard time working on the report part, computing the subtotal of the quantity per device!!

thanks in advance

attach is my code

post your existing logic and error here.

please really need your help!!!i have been working with this code for a couple of days1!!!

the error is that the subtotal of each device have been also displayed, right after each line, i wanted to display the subtotal per device only and not in the end of every line

yes,do something for me,
please point out the line which you think your logic goes wrong in that attached file?

i think because my code have been like this:

<?php
	for($i=1;$i<=$rec;$i++)
	{
		$row_det=mysql_fetch_array($res_det);
?>
			<tr>
				<td width="60" align="center"><?php print $row_det["MasterBoxNo"] ?></td>
				<td width="120" align="center"><?php print $row_det["InnerBoxNo"] ?></td>
				<td width="60" align="left"><?php print $row_det["LotNo"] ?></td>
				<td width="60" align="left"><?php print $row_det["DeviceNo"] ?></td>
				<td width="60" align="center"><?php print $row_det["NoOfLots"] ?></td>
				<td width="60" align="right"><?php print number_format($row_det["Quantity"]) ?></td>
			</tr>
	
	
			<tr>
				<td width="60" align="center"></td>
				<td width="120" align="center"></td>
				<td width="60" align="left"></td>
				<td width="60" align="left"><?php print $row_det["d2"] ?></td>
				<td width="60" align="center"></td>
				<td width="60" align="right"><?php print number_format($row_det["q2"]) ?></td>
			</tr>
<?php

it was part of the for loop thats why it was incrementing, am i right?

i dont have idea on how am i going to remove it for the for loop and be able to display the subtotal in the end of per device, do you have any idea regarding my problem?

yes, you just post required tables with data.

or tel me if this is working or not:

<!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=iso-8859-1" />
<title>PACKING GUIDE</title>
<style type="text/css">
<!--
#Layer1 {
	position:absolute;
	left:601px;
	top:157px;
	width:81px;
	height:22px;
}
#Layer2 {
	position:absolute;
	left:84px;
	top:458px;
	width:62px;
	height:13px;
	z-index:1;
}
.style4 {font-family: Tahoma; font-size: 9px; }
.style5 {font-size: 9px}
.style7 {font-family: Tahoma}
#Layer3 {
	position:absolute;
	left:88px;
	top:346px;
	width:80px;
	height:17px;
	z-index:1;
}
.style8 {
	font-size: 7px;
	font-weight: bold;
}
#Layer4 {
	position:absolute;
	left:35px;
	top:137px;
	width:103px;
	height:16px;
	z-index:2;
}
.style16 {font-family: Tahoma; font-size: 8px; }
.style17 {font-size: 8px}
.style18 {font-family: Tahoma; font-size: 8px; font-weight: bold; }
.style19 {font-family: Tahoma; font-size: 8px; color: #FFFFFF; }
-->
</style>
</head>

<body>
<?php packing_guide(); ?>
<?php packing_guide_detail(); ?>
<?php total_pg(); ?>
</body>
</html>
<?php 
function packing_guide()
{
	include("db_PSIS.php");
	$sql="SELECT tblPackingGuide.SANo, 
			tblPackingGuide.DeptID, 
			tblPackingGuide.DevCategory, 
			tblPackingGuide.PONo, 
			tblPackingGuide.PackingCategory, 
			tblPackingGuide.DateEncoded, 
			tblPackingGuide.TimeEncoded, 
			tblPackingGuide.ShipmentDate, 
			tblPackingGuide.Status, 
			tblDepartment.DepartmentName
		FROM tblDepartment 
			INNER JOIN (tblDetails INNER JOIN tblPackingGuide ON tblDetails.SANo = tblPackingGuide.SANo) ON tblDepartment.DepartmentID = tblPackingGuide.DeptID
		WHERE tblPackingGuide.SANO = (SELECT SANo FROM tblSANo_print)
		ORDER BY tblDetails.MasterBoxNo, tblDetails.InnerBoxNo, tblDetails.NoOfLots";
	$res=mysql_query($sql);
	$rec=mysql_num_rows($res);
	$row=mysql_fetch_array($res);
?>
	<table width="600" border="0" align="center" cellpadding="0" cellspacing="0" >
		<tr>
		<td align="center"><h2><b>AMERTRON INCORPORATED</h2></b>PACKING GUIDE</td>
		</tr>
		<tr>
		<td align="center"><b><?php print $row["DepartmentName"] ?></b></td>
		</tr>
	</table>
	<table width="600" border="0" align="center" cellpadding="0" cellspacing="0" >
		<tr>
		<td>SA Number:</td>
		<td><?php print $row["SANo"] ?></td>
		<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
		<td>Device Category:</td>
		<td><?php print $row["DevCategory"] ?></td>
		</tr>
		<tr>
		<td>Shipment Date:</td>
		<td><?php print $row["ShipmentDate"] ?></td>
		<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
		<td>Shipment Category:</td>
		<td><?php print $row["PackingCategory"] ?></td>
		</tr>
		<tr>
		<td>PO Number:</td>
		<td><?php print $row["PONo"] ?></td>
		<td colspan="3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
		</tr>
	</table>
	<br>
<?php
}

function packing_guide_detail()
{
	include("db_PSIS.php");
	$sql="SELECT pg1.MasterBoxNo,
					 pg1.InnerBoxNo,
					 pg1.LotNo,
					 pg1.DeviceNo,
					 pg1.NoOfLots,
					 pg1.Quantity,
					 test_2.DeviceNo as d2,
					 test_2.Quantity as q2
			  FROM pg1 LEFT JOIN test_2 ON pg1.DeviceNo=test_2.DeviceNo
			  ORDER by DeviceNo";
	
	
	$res_det=mysql_query($sql_det);
	$rec=mysql_num_rows($res_det);	
?>
		<table width="600" border="0" align="center" cellpadding="1" cellspacing="1" >
			<tr>
			<td width="60" align="center"><b>Master<br>Box No</b><br>_______</td>
			<td width="60" align="center"><b>Inner<br>Box No</b><br>_______</td>
			<td width="60" align="center"><b>Lot No</b><br><br>________________</td>
			<td width="60" align="center"><b>Device No</b><br><br>_____________________</td>
			<td width="60" align="center"><b>No of<br>Lots</b><br>_______</td>
			<td width="60" align="right"><b>Quantity</b><br><br>_________</td>
			</tr>
<?php
	    $set=1;$sub_total=0;$prev_dev_id=0;
		while($row_det=mysql_fetch_array($res_det))
		{
		if($set==1)
			{
				if($prev_dev_id==0)
				$prev_dev_id=$row_det["DeviceNo"];
				$sub_total=$sub_total+$row_det["q2"];
				$set=2;
			}
			else
			{
				if($prev_dev_id==$row_det["DeviceNo"])
				{
					$sub_total=$sub_total+$row_det["q2"];
				}
				else
				{
					$prev_dev_id=$row_det["DeviceNo"];
					$sub_total=$sub_total+$row_det["q2"];
					//$set=1;
					?>
					
			<tr>
				<td width="60" align="center"></td>
				<td width="120" align="center"></td>
				<td width="60" align="left"></td>
				<td width="60" align="left"><?php print $row_det["d2"] ?></td>
				<td width="60" align="center"></td>
				<td width="60" align="right"><?php print number_format($sub_total) ?></td>
			</tr>
					<?php 
				}
				
			}
?>
			
			<tr>
				<td width="60" align="center"><?php print $row_det["MasterBoxNo"] ?></td>
				<td width="120" align="center"><?php print $row_det["InnerBoxNo"] ?></td>
				<td width="60" align="left"><?php print $row_det["LotNo"] ?></td>
				<td width="60" align="left"><?php print $row_det["DeviceNo"] ?></td>
				<td width="60" align="center"><?php print $row_det["NoOfLots"] ?></td>
				<td width="60" align="right"><?php print number_format($row_det["Quantity"]) ?></td>
			</tr>
<?php
			
 }
?>			
	

</table>
<?php
}
function total_pg()
{
	include("db_PSIS.php");
	$sql="SELECT SANo, SUM(Quantity) AS grand_total_pg FROM pg1 WHERE SANo = (SELECT SANo FROM tblSANo_print)";
	$res=mysql_query($sql);
	$rec=mysql_num_rows($res);
	$row=mysql_fetch_array($res);
?>
	<table width="600" frame="box" align="center" cellpadding="0" cellspacing="0" >
			<tr>
				<td width="250" align="center">&nbsp;</td>
				<td></td>
				<td align="left"><b>Overall Total</b></td>
				<td align="center">&nbsp;</td>
				<td align="right"><b><?php print number_format($row["grand_total_pg"]) ?></b></td>
			</tr>
	</table>
<?php
}
?>

i think your code is working but it seems that the subtotal is wrong

the logic has been there

here is the screen shot of the error

post your database tables with data. (as .sql file)
and also try with modified code:

<!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=iso-8859-1" />
<title>PACKING GUIDE</title>
<style type="text/css">
<!--
#Layer1 {
	position:absolute;
	left:601px;
	top:157px;
	width:81px;
	height:22px;
}
#Layer2 {
	position:absolute;
	left:84px;
	top:458px;
	width:62px;
	height:13px;
	z-index:1;
}
.style4 {font-family: Tahoma; font-size: 9px; }
.style5 {font-size: 9px}
.style7 {font-family: Tahoma}
#Layer3 {
	position:absolute;
	left:88px;
	top:346px;
	width:80px;
	height:17px;
	z-index:1;
}
.style8 {
	font-size: 7px;
	font-weight: bold;
}
#Layer4 {
	position:absolute;
	left:35px;
	top:137px;
	width:103px;
	height:16px;
	z-index:2;
}
.style16 {font-family: Tahoma; font-size: 8px; }
.style17 {font-size: 8px}
.style18 {font-family: Tahoma; font-size: 8px; font-weight: bold; }
.style19 {font-family: Tahoma; font-size: 8px; color: #FFFFFF; }
-->
</style>
</head>

<body>
<?php packing_guide(); ?>
<?php packing_guide_detail(); ?>
<?php total_pg(); ?>
</body>
</html>
<?php 
function packing_guide()
{
	include("db_PSIS.php");
	$sql="SELECT tblPackingGuide.SANo, 
			tblPackingGuide.DeptID, 
			tblPackingGuide.DevCategory, 
			tblPackingGuide.PONo, 
			tblPackingGuide.PackingCategory, 
			tblPackingGuide.DateEncoded, 
			tblPackingGuide.TimeEncoded, 
			tblPackingGuide.ShipmentDate, 
			tblPackingGuide.Status, 
			tblDepartment.DepartmentName
		FROM tblDepartment 
			INNER JOIN (tblDetails INNER JOIN tblPackingGuide ON tblDetails.SANo = tblPackingGuide.SANo) ON tblDepartment.DepartmentID = tblPackingGuide.DeptID
		WHERE tblPackingGuide.SANO = (SELECT SANo FROM tblSANo_print)
		ORDER BY tblDetails.MasterBoxNo, tblDetails.InnerBoxNo, tblDetails.NoOfLots";
	$res=mysql_query($sql);
	$rec=mysql_num_rows($res);
	$row=mysql_fetch_array($res);
?>
	<table width="600" border="0" align="center" cellpadding="0" cellspacing="0" >
		<tr>
		<td align="center"><h2><b>AMERTRON INCORPORATED</h2></b>PACKING GUIDE</td>
		</tr>
		<tr>
		<td align="center"><b><?php print $row["DepartmentName"] ?></b></td>
		</tr>
	</table>
	<table width="600" border="0" align="center" cellpadding="0" cellspacing="0" >
		<tr>
		<td>SA Number:</td>
		<td><?php print $row["SANo"] ?></td>
		<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
		<td>Device Category:</td>
		<td><?php print $row["DevCategory"] ?></td>
		</tr>
		<tr>
		<td>Shipment Date:</td>
		<td><?php print $row["ShipmentDate"] ?></td>
		<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
		<td>Shipment Category:</td>
		<td><?php print $row["PackingCategory"] ?></td>
		</tr>
		<tr>
		<td>PO Number:</td>
		<td><?php print $row["PONo"] ?></td>
		<td colspan="3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
		</tr>
	</table>
	<br>
<?php
}

function packing_guide_detail()
{
	include("db_PSIS.php");
	$sql="SELECT pg1.MasterBoxNo,
					 pg1.InnerBoxNo,
					 pg1.LotNo,
					 pg1.DeviceNo,
					 pg1.NoOfLots,
					 pg1.Quantity,
					 test_2.DeviceNo as d2,
					 test_2.Quantity as q2
			  FROM pg1 LEFT JOIN test_2 ON pg1.DeviceNo=test_2.DeviceNo
			  ORDER by DeviceNo";
	
	
	$res_det=mysql_query($sql_det);
	$rec=mysql_num_rows($res_det);	
?>
		<table width="600" border="0" align="center" cellpadding="1" cellspacing="1" >
			<tr>
			<td width="60" align="center"><b>Master<br>Box No</b><br>_______</td>
			<td width="60" align="center"><b>Inner<br>Box No</b><br>_______</td>
			<td width="60" align="center"><b>Lot No</b><br><br>________________</td>
			<td width="60" align="center"><b>Device No</b><br><br>_____________________</td>
			<td width="60" align="center"><b>No of<br>Lots</b><br>_______</td>
			<td width="60" align="right"><b>Quantity</b><br><br>_________</td>
			</tr>
<?php
	    $set=1;$sub_total=0;$prev_dev_id=0;
		while($row_det=mysql_fetch_array($res_det))
		{
		if($set==1)
			{
				if($prev_dev_id==0)
				$prev_dev_id=$row_det["DeviceNo"];
				$sub_total=$sub_total+$row_det["q2"];
				$set=2;
			}
			else
			{
				if($prev_dev_id==$row_det["DeviceNo"])
				{
					$sub_total=$sub_total+$row_det["q2"];
				}
				else
				{
					$prev_dev_id=$row_det["DeviceNo"];
					$sub_total=0;
					$sub_total=$sub_total+$row_det["q2"];
					//$set=1;
					?>
					
			<tr>
				<td width="60" align="center"></td>
				<td width="120" align="center"></td>
				<td width="60" align="left"></td>
				<td width="60" align="left"><?php print $prev_dev_id ?></td>
				<td width="60" align="center"></td>
				<td width="60" align="right"><?php print number_format($sub_total) ?></td>
			</tr>
					<?php 
				}
				
			}
?>
			
			<tr>
				<td width="60" align="center"><?php print $row_det["MasterBoxNo"] ?></td>
				<td width="120" align="center"><?php print $row_det["InnerBoxNo"] ?></td>
				<td width="60" align="left"><?php print $row_det["LotNo"] ?></td>
				<td width="60" align="left"><?php print $row_det["DeviceNo"] ?></td>
				<td width="60" align="center"><?php print $row_det["NoOfLots"] ?></td>
				<td width="60" align="right"><?php print number_format($row_det["Quantity"]) ?></td>
			</tr>
<?php
			
 }
?>			
	

</table>
<?php
}
function total_pg()
{
	include("db_PSIS.php");
	$sql="SELECT SANo, SUM(Quantity) AS grand_total_pg FROM pg1 WHERE SANo = (SELECT SANo FROM tblSANo_print)";
	$res=mysql_query($sql);
	$rec=mysql_num_rows($res);
	$row=mysql_fetch_array($res);
?>
	<table width="600" frame="box" align="center" cellpadding="0" cellspacing="0" >
			<tr>
				<td width="250" align="center">&nbsp;</td>
				<td></td>
				<td align="left"><b>Overall Total</b></td>
				<td align="center">&nbsp;</td>
				<td align="right"><b><?php print number_format($row["grand_total_pg"]) ?></b></td>
			</tr>
	</table>
<?php
}
?>

i just wrote this code by guessing, i cannot test this because i don't have your table and data in that table.
So if you can please post the table, i will hav a clear look on that.

here is the database, i think i have already corected the subtotal but there is a device missing

here is the database

??????

hi Shanti Chepuru, your code is working, but i the first device is missing?

sorry but i think i made some mistakes in my database attachment

attached is the result of the code you have given me, i think the first device is missing,

yes i have tried that, and make some changes regarding the sub total:

<!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=iso-8859-1" />
<title>PACKING GUIDE</title>
<style type="text/css">
<!--
#Layer1 {
	position:absolute;
	left:601px;
	top:157px;
	width:81px;
	height:22px;
}
#Layer2 {
	position:absolute;
	left:84px;
	top:458px;
	width:62px;
	height:13px;
	z-index:1;
}
.style4 {font-family: Tahoma; font-size: 9px; }
.style5 {font-size: 9px}
.style7 {font-family: Tahoma}
#Layer3 {
	position:absolute;
	left:88px;
	top:346px;
	width:80px;
	height:17px;
	z-index:1;
}
.style8 {
	font-size: 7px;
	font-weight: bold;
}
#Layer4 {
	position:absolute;
	left:35px;
	top:137px;
	width:103px;
	height:16px;
	z-index:2;
}
.style16 {font-family: Tahoma; font-size: 8px; }
.style17 {font-size: 8px}
.style18 {font-family: Tahoma; font-size: 8px; font-weight: bold; }
.style19 {font-family: Tahoma; font-size: 8px; color: #FFFFFF; }
-->
</style>
</head>

<body>
<?php packing_guide(); ?>
<?php packing_guide_detail(); ?>
<?php total_pg(); ?>
</body>
</html>
<?php 
function packing_guide()
{
	include("db_PSIS.php");
	$sql="SELECT tblPackingGuide.SANo, 
			tblPackingGuide.DeptID, 
			tblPackingGuide.DevCategory, 
			tblPackingGuide.PONo, 
			tblPackingGuide.PackingCategory, 
			tblPackingGuide.DateEncoded, 
			tblPackingGuide.TimeEncoded, 
			tblPackingGuide.ShipmentDate, 
			tblPackingGuide.Status, 
			tblDepartment.DepartmentName
		FROM tblDepartment 
			INNER JOIN (tblDetails INNER JOIN tblPackingGuide ON tblDetails.SANo = tblPackingGuide.SANo) ON tblDepartment.DepartmentID = tblPackingGuide.DeptID
		WHERE tblPackingGuide.SANO = (SELECT SANo FROM tblSANo_print)
		ORDER BY tblDetails.MasterBoxNo, tblDetails.InnerBoxNo, tblDetails.NoOfLots";
	$res=mysql_query($sql);
	$rec=mysql_num_rows($res);
	$row=mysql_fetch_array($res);
?>
	<table width="600" border="0" align="center" cellpadding="0" cellspacing="0" >
		<tr>
		<td align="center"><h2><b>AMERTRON INCORPORATED</h2></b>PACKING GUIDE</td>
		</tr>
		<tr>
		<td align="center"><b><?php print $row["DepartmentName"] ?></b></td>
		</tr>
	</table>
	<table width="600" border="0" align="center" cellpadding="0" cellspacing="0" >
		<tr>
		<td>SA Number:</td>
		<td><?php print $row["SANo"] ?></td>
		<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
		<td>Device Category:</td>
		<td><?php print $row["DevCategory"] ?></td>
		</tr>
		<tr>
		<td>Shipment Date:</td>
		<td><?php print $row["ShipmentDate"] ?></td>
		<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
		<td>Shipment Category:</td>
		<td><?php print $row["PackingCategory"] ?></td>
		</tr>
		<tr>
		<td>PO Number:</td>
		<td><?php print $row["PONo"] ?></td>
		<td colspan="3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
		</tr>
	</table>
	<br>
<?php
}

function packing_guide_detail()
{
	include("db_PSIS.php");
	$sql_det="SELECT pg1.MasterBoxNo,
					 pg1.InnerBoxNo,
					 pg1.LotNo,
					 pg1.DeviceNo,
					 pg1.NoOfLots,
					 pg1.Quantity,
					 test_2.DeviceNo as d2,
					 test_2.Quantity as q2
			  FROM pg1 LEFT JOIN test_2 ON pg1.DeviceNo=test_2.DeviceNo
			  ORDER by DeviceNo";
	$res_det=mysql_query($sql_det);
	$rec=mysql_num_rows($res_det);	
?>
		<table width="600" border="0" align="center" cellpadding="1" cellspacing="1" >
			<tr>
			<td width="60" align="center"><b>Master<br>Box No</b><br>_______</td>
			<td width="60" align="center"><b>Inner<br>Box No</b><br>_______</td>
			<td width="60" align="center"><b>Lot No</b><br><br>________________</td>
			<td width="60" align="center"><b>Device No</b><br><br>_____________________</td>
			<td width="60" align="center"><b>No of<br>Lots</b><br>_______</td>
			<td width="60" align="right"><b>Quantity</b><br><br>_________</td>
			</tr>
<?php
 
      $set=1;$sub_total=0;$prev_dev_id=0;
      while($row_det=mysql_fetch_array($res_det))
      {
		if($set==1)
      {
		if($prev_dev_id==0)
		$prev_dev_id=$row_det["DeviceNo"];
		$sub_total=$row_det["q2"];
		$set=2;
      }
		else
      {
		if($prev_dev_id==$row_det["DeviceNo"])
      {
		$sub_total=$row_det["q2"];
      }
      else
      {
      $prev_dev_id=$row_det["DeviceNo"];
	  $sub_total=0;
      $sub_total=$row_det["q2"];
      //$set=1;
      ?>
			
			<tr>
				<td width="60" align="center"></td>
				<td width="120" align="center"></td>
				<td width="60" align="left"></td>
				<td width="60" align="left"><?php print $row_det["DeviceNo"] ?></td>
				<td width="60" align="center"></td>
				<td width="60" align="right"><?php print number_format($sub_total) ?></td>
			</tr>
      <?php
      }
      }
      ?>
			<tr>
				<td width="60" align="center"><?php print $row_det["MasterBoxNo"] ?></td>
				<td width="120" align="center"><?php print $row_det["InnerBoxNo"] ?></td>
				<td width="60" align="left"><?php print $row_det["LotNo"] ?></td>
				<td width="60" align="left"><?php print $row_det["DeviceNo"] ?></td>
				<td width="60" align="center"><?php print $row_det["NoOfLots"] ?></td>
				<td width="60" align="right"><?php print number_format($row_det["Quantity"]) ?></td>
			</tr>
      <?php
      }
      ?>
      </table>
      <?php

      }
function total_pg()
{
	include("db_PSIS.php");
	$sql="SELECT SANo, SUM(Quantity) AS grand_total_pg FROM pg1 WHERE SANo = (SELECT SANo FROM tblSANo_print)";
	$res=mysql_query($sql);
	$rec=mysql_num_rows($res);
	$row=mysql_fetch_array($res);
?>
	<table width="600" frame="box" align="center" cellpadding="0" cellspacing="0" >
			<tr>
				<td width="250" align="center">&nbsp;</td>
				<td></td>
				<td align="left"><b>Overall Total</b></td>
				<td align="center">&nbsp;</td>
				<td align="right"><b><?php print number_format($row["grand_total_pg"]) ?></b></td>
			</tr>
	</table>
<?php
}
?>

the only problem left is the first device have been missing, and the subtotal of other devices have been place in the beginning not in the end of the device

try with this:

<!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=iso-8859-1" />
<title>PACKING GUIDE</title>
<style type="text/css">
<!--
#Layer1 {
position:absolute;
left:601px;
top:157px;
width:81px;
height:22px;
}
#Layer2 {
position:absolute;
left:84px;
top:458px;
width:62px;
height:13px;
z-index:1;
}
.style4 {font-family: Tahoma; font-size: 9px; }
.style5 {font-size: 9px}
.style7 {font-family: Tahoma}
#Layer3 {
position:absolute;
left:88px;
top:346px;
width:80px;
height:17px;
z-index:1;
}
.style8 {
font-size: 7px;
font-weight: bold;
}
#Layer4 {
position:absolute;
left:35px;
top:137px;
width:103px;
height:16px;
z-index:2;
}
.style16 {font-family: Tahoma; font-size: 8px; }
.style17 {font-size: 8px}
.style18 {font-family: Tahoma; font-size: 8px; font-weight: bold; }
.style19 {font-family: Tahoma; font-size: 8px; color: #FFFFFF; }
-->
</style>
</head>

<body>
<?php packing_guide(); ?>
<?php packing_guide_detail(); ?>
<?php total_pg(); ?>
</body>
</html>
<?php
function packing_guide()
{
include("db_PSIS.php");
$sql="SELECT tblPackingGuide.SANo,
tblPackingGuide.DeptID,
tblPackingGuide.DevCategory,
tblPackingGuide.PONo,
tblPackingGuide.PackingCategory,
tblPackingGuide.DateEncoded,
tblPackingGuide.TimeEncoded,
tblPackingGuide.ShipmentDate,
tblPackingGuide.Status,
tblDepartment.DepartmentName
FROM tblDepartment
INNER JOIN (tblDetails INNER JOIN tblPackingGuide ON tblDetails.SANo = tblPackingGuide.SANo) ON tblDepartment.DepartmentID = tblPackingGuide.DeptID
WHERE tblPackingGuide.SANO = (SELECT SANo FROM tblSANo_print)
ORDER BY tblDetails.MasterBoxNo, tblDetails.InnerBoxNo, tblDetails.NoOfLots";
$res=mysql_query($sql);
$rec=mysql_num_rows($res);
$row=mysql_fetch_array($res);
?>
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0" >
<tr>
<td align="center"><h2><b>AMERTRON INCORPORATED</h2></b>PACKING GUIDE</td>
</tr>
<tr>
<td align="center"><b><?php print $row["DepartmentName"] ?></b></td>
</tr>
</table>
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0" >
<tr>
<td>SA Number:</td>
<td><?php print $row["SANo"] ?></td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td>Device Category:</td>
<td><?php print $row["DevCategory"] ?></td>
</tr>
<tr>
<td>Shipment Date:</td>
<td><?php print $row["ShipmentDate"] ?></td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td>Shipment Category:</td>
<td><?php print $row["PackingCategory"] ?></td>
</tr>
<tr>
<td>PO Number:</td>
<td><?php print $row["PONo"] ?></td>
<td colspan="3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
</tr>
</table>
<br>
<?php
}

function packing_guide_detail()
{
include("db_PSIS.php");
$sql_det="SELECT pg1.MasterBoxNo,
pg1.InnerBoxNo,
pg1.LotNo,
pg1.DeviceNo,
pg1.NoOfLots,
pg1.Quantity,
test_2.DeviceNo as d2,
test_2.Quantity as q2
FROM pg1 LEFT JOIN test_2 ON pg1.DeviceNo=test_2.DeviceNo
ORDER by DeviceNo";
$res_det=mysql_query($sql_det);
$rec=mysql_num_rows($res_det);
?>
<table width="600" border="0" align="center" cellpadding="1" cellspacing="1" >
<tr>
<td width="60" align="center"><b>Master<br>Box No</b><br>_______</td>
<td width="60" align="center"><b>Inner<br>Box No</b><br>_______</td>
<td width="60" align="center"><b>Lot No</b><br><br>________________</td>
<td width="60" align="center"><b>Device No</b><br><br>_____________________</td>
<td width="60" align="center"><b>No of<br>Lots</b><br>_______</td>
<td width="60" align="right"><b>Quantity</b><br><br>_________</td>
</tr>
<?php

$set=1;$sub_total=0;$prev_dev_id=0;
while($row_det=mysql_fetch_array($res_det))
{
if($set==1)
{
if($prev_dev_id==0)
$prev_dev_id=$row_det["DeviceNo"];
$sub_total=$row_det["q2"];
$set=2;
}
else
{
if($prev_dev_id==$row_det["DeviceNo"])
{
$sub_total=$row_det["q2"];
}
else
{
$prev_dev_id=$row_det["DeviceNo"];
$sub_total=0;
$sub_total=$row_det["q2"];
//$set=1;
?>

<tr>
<td width="60" align="center"></td>
<td width="120" align="center"></td>
<td width="60" align="left"></td>
<td width="60" align="left"><?php print $prev_dev_id ?></td>
<td width="60" align="center"></td>
<td width="60" align="right"><?php print number_format($sub_total) ?></td>
</tr>
<?php
}
}
?>
<tr>
<td width="60" align="center"><?php print $row_det["MasterBoxNo"] ?></td>
<td width="120" align="center"><?php print $row_det["InnerBoxNo"] ?></td>
<td width="60" align="left"><?php print $row_det["LotNo"] ?></td>
<td width="60" align="left"><?php print $row_det["DeviceNo"] ?></td>
<td width="60" align="center"><?php print $row_det["NoOfLots"] ?></td>
<td width="60" align="right"><?php print number_format($row_det["Quantity"]) ?></td>
</tr>
<?php
}
?>
</table>
<?php

}
function total_pg()
{
include("db_PSIS.php");
$sql="SELECT SANo, SUM(Quantity) AS grand_total_pg FROM pg1 WHERE SANo = (SELECT SANo FROM tblSANo_print)";
$res=mysql_query($sql);
$rec=mysql_num_rows($res);
$row=mysql_fetch_array($res);
?>
<table width="600" frame="box" align="center" cellpadding="0" cellspacing="0" >
<tr>
<td width="250" align="center">&nbsp;</td>
<td></td>
<td align="left"><b>Overall Total</b></td>
<td align="center">&nbsp;</td>
<td align="right"><b><?php print number_format($row["grand_total_pg"]) ?></b></td>
</tr>
</table>
<?php
}
?>

i got the same result as the last screen shot i have sent to you, there no changes

again try with this:

<!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=iso-8859-1" />
<title>PACKING GUIDE</title>
<style type="text/css">
<!--
#Layer1 {
position:absolute;
left:601px;
top:157px;
width:81px;
height:22px;
}
#Layer2 {
position:absolute;
left:84px;
top:458px;
width:62px;
height:13px;
z-index:1;
}
.style4 {font-family: Tahoma; font-size: 9px; }
.style5 {font-size: 9px}
.style7 {font-family: Tahoma}
#Layer3 {
position:absolute;
left:88px;
top:346px;
width:80px;
height:17px;
z-index:1;
}
.style8 {
font-size: 7px;
font-weight: bold;
}
#Layer4 {
position:absolute;
left:35px;
top:137px;
width:103px;
height:16px;
z-index:2;
}
.style16 {font-family: Tahoma; font-size: 8px; }
.style17 {font-size: 8px}
.style18 {font-family: Tahoma; font-size: 8px; font-weight: bold; }
.style19 {font-family: Tahoma; font-size: 8px; color: #FFFFFF; }
-->
</style>
</head>

<body>
<?php packing_guide(); ?>
<?php packing_guide_detail(); ?>
<?php total_pg(); ?>
</body>
</html>
<?php
function packing_guide()
{
include("db_PSIS.php");
$sql="SELECT tblPackingGuide.SANo,
tblPackingGuide.DeptID,
tblPackingGuide.DevCategory,
tblPackingGuide.PONo,
tblPackingGuide.PackingCategory,
tblPackingGuide.DateEncoded,
tblPackingGuide.TimeEncoded,
tblPackingGuide.ShipmentDate,
tblPackingGuide.Status,
tblDepartment.DepartmentName
FROM tblDepartment
INNER JOIN (tblDetails INNER JOIN tblPackingGuide ON tblDetails.SANo = tblPackingGuide.SANo) ON tblDepartment.DepartmentID = tblPackingGuide.DeptID
WHERE tblPackingGuide.SANO = (SELECT SANo FROM tblSANo_print)
ORDER BY tblDetails.MasterBoxNo, tblDetails.InnerBoxNo, tblDetails.NoOfLots";
$res=mysql_query($sql);
$rec=mysql_num_rows($res);
$row=mysql_fetch_array($res);
?>
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0" >
<tr>
<td align="center"><h2><b>AMERTRON INCORPORATED</h2></b>PACKING GUIDE</td>
</tr>
<tr>
<td align="center"><b><?php print $row["DepartmentName"] ?></b></td>
</tr>
</table>
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0" >
<tr>
<td>SA Number:</td>
<td><?php print $row["SANo"] ?></td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td>Device Category:</td>
<td><?php print $row["DevCategory"] ?></td>
</tr>
<tr>
<td>Shipment Date:</td>
<td><?php print $row["ShipmentDate"] ?></td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td>Shipment Category:</td>
<td><?php print $row["PackingCategory"] ?></td>
</tr>
<tr>
<td>PO Number:</td>
<td><?php print $row["PONo"] ?></td>
<td colspan="3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
</tr>
</table>
<br>
<?php
}

function packing_guide_detail()
{
include("db_PSIS.php");
$sql_det="SELECT pg1.MasterBoxNo,
pg1.InnerBoxNo,
pg1.LotNo,
pg1.DeviceNo,
pg1.NoOfLots,
pg1.Quantity,
test_2.DeviceNo as d2,
test_2.Quantity as q2
FROM pg1 LEFT JOIN test_2 ON pg1.DeviceNo=test_2.DeviceNo
ORDER by DeviceNo";
$res_det=mysql_query($sql_det);
$rec=mysql_num_rows($res_det);
?>
<table width="600" border="0" align="center" cellpadding="1" cellspacing="1" >
<tr>
<td width="60" align="center"><b>Master<br>Box No</b><br>_______</td>
<td width="60" align="center"><b>Inner<br>Box No</b><br>_______</td>
<td width="60" align="center"><b>Lot No</b><br><br>________________</td>
<td width="60" align="center"><b>Device No</b><br><br>_____________________</td>
<td width="60" align="center"><b>No of<br>Lots</b><br>_______</td>
<td width="60" align="right"><b>Quantity</b><br><br>_________</td>
</tr>
<?php

$set=1;$sub_total=0;$prev_dev_id=0;
while($row_det=mysql_fetch_array($res_det))
{
if($set==1)
{
if($prev_dev_id==0)
$prev_dev_id=$row_det["DeviceNo"];
$sub_total=$row_det["q2"];
$set=2;
}
else
{
if($prev_dev_id==$row_det["DeviceNo"])
{
$sub_total=$row_det["q2"];
}
else
{

?>

<tr>
<td width="60" align="center"></td>
<td width="120" align="center"></td>
<td width="60" align="left"></td>
<td width="60" align="left"><?php print $prev_dev_id ?></td>
<td width="60" align="center"></td>
<td width="60" align="right"><?php print number_format($sub_total) ?></td>
</tr>
<?php
$prev_dev_id=$row_det["DeviceNo"];
$sub_total=0;
$sub_total=$row_det["q2"];
//$set=1;
}
}
?>
<tr>
<td width="60" align="center"><?php print $row_det["MasterBoxNo"] ?></td>
<td width="120" align="center"><?php print $row_det["InnerBoxNo"] ?></td>
<td width="60" align="left"><?php print $row_det["LotNo"] ?></td>
<td width="60" align="left"><?php print $row_det["DeviceNo"] ?></td>
<td width="60" align="center"><?php print $row_det["NoOfLots"] ?></td>
<td width="60" align="right"><?php print number_format($row_det["Quantity"]) ?></td>
</tr>
<?php
}
?>
</table>
<?php

}
function total_pg()
{
include("db_PSIS.php");
$sql="SELECT SANo, SUM(Quantity) AS grand_total_pg FROM pg1 WHERE SANo = (SELECT SANo FROM tblSANo_print)";
$res=mysql_query($sql);
$rec=mysql_num_rows($res);
$row=mysql_fetch_array($res);
?>
<table width="600" frame="box" align="center" cellpadding="0" cellspacing="0" >
<tr>
<td width="250" align="center">&nbsp;</td>
<td></td>
<td align="left"><b>Overall Total</b></td>
<td align="center">&nbsp;</td>
<td align="right"><b><?php print number_format($row["grand_total_pg"]) ?></b></td>
</tr>
</table>
<?php
}
?>

or else send your db table with data.
i can't check actual result until i get them.

hope you can help to solve my problem, thanks a lot

hi Shanti Chepuru, the first device has been displayed now, but the last device isnow missing

i have some work now, please check this small issue yourself, it is not much difficult to do. Its a just our login mistake.
Whenever i got time, then i will work on this.
Sorry and thanks.

hi already solve my problem thanks a lot for your help

then mark this thread as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.