求一填值效果
能否达到如图所示的效果,例如当总数量为240时,紫色的第一个单元格为120,第二个单元格为240-120=120。
图中关系如下:
一个stockno对应多个行,图中为两行。如果是一个页面对应多个stockno,则$arrs对应的count总数,去除掉赋给第一个stockno的count值,剩余的值赋给接下来的stockno对应的紫色框中的值。
所示代码如下:
<?php
$sql = "select DISTINCT b.packageno,a.stock_no from `stock_detail` as a,`kw_manage` as b where a.stock_no = '".$stockno[$j-1]."' and a.cust_no = replace( b.cust_no, ' ', '' )";
//echo $sql.'<br />';
$result = mysql_query($sql);
$res = array();
while($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
$sql2 = "select lotno,count(lotno) from `vp_barcode_2d_y` where packageno = '".$row['packageno']."' group by lotno,packageno order by lotno asc";
//echo $sql2.'<br />';
$result2 = mysql_query($sql2);
$var = array();
while($row2 = mysql_fetch_array($result2,MYSQL_NUM))
{
if(isset($res[$row2[0]]))
$res[$row2[0]]['count'] += $row2[1];
else
$res[$row2[0]] = array('lotno'=>$row2[0],'count'=>$row2[1]);
}
}
ksort($res);
$arrs = array();
foreach($res as $v2)
{
$arrs[] = $v2;
}
print_r($arrs);//Array ( [0] => Array ( [lotno] => 3207 [count] => 240 ) )
$sql4 = "select arr_time,c_type,cust_no,snp,mount,mount*snp as m_total from `".$t."` where stock_no = '".$stockno[$j-1]."'";
$result4 = mysql_query($sql4);
$a = array();
while($var = mysql_fetch_array($result4,MYSQL_NUM))
{
$a[] = $var;
}
foreach($a as $k=>$v)//显示一个stockno对应的两行结果
{
echo '
<tr height="56" style="height: 42.0pt">
<td>
'.($k+1).'</td>';
?>
<td>
<?php
echo $v['0'];
?></td>
<td>
<?php
echo $v['1'];
?></td>
<td>
<?php
echo $v['2'];
?></td>
<td>
<?php
$sql = "select type from `kw_info` where cust_no = '".$v['2']."'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result,MYSQL_ASSOC);
echo $row['type'];
?></td>
<td>
<?php
echo $v['3'];
?></td>
<td>
<?php
echo $v['4'];
?></td>
<td>
<?php
if(($arr_mount[$j-1]['mount']%$kx) != 0 )
echo $kx-($arr_mount[$j-1]['mount']%$kx);
else
echo '0';
?></td>
<td>
<?php
echo $v['5'];
echo '</td>';
echo '<td>';
//需加入的代码部分;
echo '</td>';
echo '
<td>
</td>
<td>
</td>
<td> </td>
</tr>';
}
?>