当前位置:Gxlcms > PHP教程 > 求一填值成效

求一填值成效

时间:2021-07-01 10:21:17 帮助过:4人阅读

求一填值效果
本帖最后由 lazygc520 于 2013-06-28 17:35:24 编辑

图片如下:


能否达到如图所示的效果,例如当总数量为240时,紫色的第一个单元格为120,第二个单元格为240-120=120。
图中关系如下:

一个stockno对应多个行,图中为两行。如果是一个页面对应多个stockno,则$arrs对应的count总数,去除掉赋给第一个stockno的count值,剩余的值赋给接下来的stockno对应的紫色框中的值。

所示代码如下:

$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.'
';
$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.'
';
$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 '


'.($k+1).'';
?>

echo $v['0'];
?>

echo $v['1'];
?>

echo $v['2'];
?>

$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'];

人气教程排行