本帖最后由 lazygc520 于 2013-06-28 17:35:24 编辑
图片如下:
能否达到如图所示的效果,例如当总数量为240时,紫色的第一个单元格为120,第二个单元格为240-120=120。
图中关系如下:
一个stockno对应多个行,图中为两行。如果是一个页面对应多个stockno,则$arrs对应的count总数,去除掉赋给第一个stockno的count值,剩余的值赋给接下来的stockno对应的紫色框中的值。
所示代码如下:
<br>
<?php <br />
$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, ' ', '' )";<br>
// echo $sql.'<br>';<br>
$result = mysql_query($sql);<br>
$res = array(); <br>
while($row = mysql_fetch_array($result,MYSQL_ASSOC))<br>
{<br>
$sql2 = "select lotno,count(lotno) from `vp_barcode_2d_y` where packageno = '".$row['packageno']."' group by lotno,packageno order by lotno asc";<br>
// echo $sql2.'<br>';<br>
$result2 = mysql_query($sql2);<br>
$var = array();<br>
while($row2 = mysql_fetch_array($result2,MYSQL_NUM))<br>
{<br>
if(isset($res[$row2[0]])) <br>
$res[$row2[0]]['count'] += $row2[1];<br>
else <br>
$res[$row2[0]] = array('lotno'=>$row2[0],'count'=>$row2[1]);<br>
}<br>
}<br>
ksort($res);<br>
$arrs = array();<br>
foreach($res as $v2)<br>
{<br>
$arrs[] = $v2;<br>
}<br>
print_r($arrs);//Array ( [0] => Array ( [lotno] => 3207 [count] => 240 ) ) <br>
<br>
<br>
$sql4 = "select arr_time,c_type,cust_no,snp,mount,mount*snp as m_total from `".$t."` where stock_no = '".$stockno[$j-1]."'";<br>
$result4 = mysql_query($sql4);<br>
$a = array();<br>
while($var = mysql_fetch_array($result4,MYSQL_NUM))<br>
{<br>
$a[] = $var;<br>
}<br>
foreach($a as $k=>$v)//显示一个stockno对应的两行结果<br>
{<br>
echo '<br>
<tr>
<br>
<td>
<br>
'.($k+1).'</td>';<br>
?><br>
<td>
<br>
<?php <br />
echo $v['0'];<br>
?></td>
<br>
<td>
<br>
<?php <br />
echo $v['1'];<br>
?></td>
<br>
<td>
<br>
<?php <br />
echo $v['2'];<br>
?></td>
<br>
<td>
<br>
<?php <br />
$sql = "select type from `kw_info` where cust_no = '".$v['2']."'";<br>
$result = mysql_query($sql);<br>
$row = mysql_fetch_array($result,MYSQL_ASSOC);<br>
echo $row['type']; <div class="clear">
</div>
</td>
</tr>