没有看到 unse 在哪里
请说明需求
请说明需求
解决方案 »
- 网站在线计数统计数据莫名变很大的问题,在线等!
- Warning: shell_exec() [function.shell-exec]: Unable to execute 如何解决啊
- longtext 插入错误!
- 本机上正常,服务器上网站不能用!!!急啊!!!!
- php里面如何插入或者更新access数据库
- 已知http://topic.csdn.net/ui/images/logo_csdn.gif和logo_csdn.gif,求http://topic.csdn.net/ui/images/
- 统计一下php程序员每个月的有效代码量。
- 为什么这段代码运行后是空白呢?
- 我的问题去哪了?
- 在PHP中怎样实现跳转到其它页?
- 求教一维数据转多维
- thinkphp 引入模板文件
col1:
select cust_no,total=SUM(mount)*snp from dfl_stock_detail where po_num = 'SU14031300627' and cust_no = '237033AW0A' group by cust_no,snpArray ( [0] => Array ( [0] => 237033AW0A [cust_no] => 237033AW0A [1] => 375 [total] => 375 ) )col2:
select cust_no,total=SUM(mount)*snp from dfl_stock_detail where po_num = 'SU14031300627' and cust_no = '237033RC3A' group by cust_no,snpArray ( [0] => Array ( [0] => 237033RC3A [cust_no] => 237033RC3A [1] => 75 [total] => 75 ) ) 按照$b值的不同求对应的$ress的值。
//已知数组a:
array (
0 =>
array (
0 => '12653627',
'cust_no' => '12653627',
1 => '4069',
'lotno' => '4069',
2 => 19,
'part_count' => 19,
),
1 =>
array (
0 => '12653627',
'cust_no' => '12653627',
1 => '4071',
'lotno' => '4071',
2 => 146,
'part_count' => 146,
),
2 =>
array (
0 => '12654172',
'cust_no' => '12654172',
1 => '4071',
'lotno' => '4071',
2 => 855,
'part_count' => 855,
),
3 =>
array (
0 => '237033AW0A',
'cust_no' => '237033AW0A',
1 => '4409',
'lotno' => '4409',
2 => 300,
'part_count' => 300,
),
4 =>
array (
0 => '237033AW0A',
'cust_no' => '237033AW0A',
1 => '4410',
'lotno' => '4410',
2 => 141,
'part_count' => 141,
),
5 =>
array (
0 => '237033RC3A ',
'cust_no' => '237033RC3A ',
1 => '4418',
'lotno' => '4418',
2 => 80,
'part_count' => 80,
),
6 =>
array (
0 => '237033TC0A',
'cust_no' => '237033TC0A',
1 => '4401',
'lotno' => '4401',
2 => 2,
'part_count' => 2,
),
7 =>
array (
0 => '237033TC0A',
'cust_no' => '237033TC0A',
1 => '4402',
'lotno' => '4402',
2 => 1,
'part_count' => 1,
),
8 =>
array (
0 => '237033TC0A',
'cust_no' => '237033TC0A',
1 => '4408',
'lotno' => '4408',
2 => 178,
'part_count' => 178,
),
9 =>
array (
0 => '237033TC0A',
'cust_no' => '237033TC0A',
1 => '4409',
'lotno' => '4409',
2 => 374,
'part_count' => 374,
),
)//数组b
array (
0 =>
array (
'cust_no' => '237033AW0A',
'total' => 375,
),
1 =>
array (
'cust_no' => '237033RC3A',
'total' => 75,
),
)
数组a与数组b匹配,当数组a的cust_no和数量满足数组b的cust_no和数量时。需要$ress求得的类似结果如下:Array
(
[0] => Array
(
[cust_no] => 237033AW0A
[lotno] => 4409
[part_count] => 300
) [1] => Array
(
[cust_no] => 237033AW0A
[lotno] => 4410
[part_count] => 75
) [2] => Array
(
[cust_no] => 237033RC3A
[lotno] => 4418
[part_count] => 75
))这样的话可否实现?或者放在如1#的循环中,当数组b值为多少时,对应的数组a的匹配结果为多少?$ress值被赋值后如何重置?
0 =>
array (
'cust_no' => '12653627',
'lotno' => '4069',
'part_count' => 19,
),
1 =>
array (
'cust_no' => '12653627',
'lotno' => '4071',
'part_count' => 146,
),
2 =>
array (
'cust_no' => '12654172',
'lotno' => '4071',
'part_count' => 855,
),
3 =>
array (
'cust_no' => '237033AW0A',
'lotno' => '4409',
'part_count' => 300,
),
4 =>
array (
'cust_no' => '237033AW0A',
'lotno' => '4410',
'part_count' => 141,
),
5 =>
array (
'cust_no' => '237033RC3A',
'lotno' => '4418',
'part_count' => 80,
),
6 =>
array (
'cust_no' => '237033TC0A',
'lotno' => '4401',
'part_count' => 2,
),
7 =>
array (
'cust_no' => '237033TC0A',
'lotno' => '4402',
'part_count' => 1,
),
8 =>
array (
'cust_no' => '237033TC0A',
'lotno' => '4408',
'part_count' => 178,
),
9 =>
array (
'cust_no' => '237033TC0A',
'lotno' => '4409',
'part_count' => 374,
),
);
$b = array (
0 =>
array (
'cust_no' => '237033AW0A',
'total' => 375,
),
1 =>
array (
'cust_no' => '237033RC3A',
'total' => 75,
),
);foreach($b as $d) {
$k = $d['cust_no'];
reset($a);
foreach($a as $r) {
if($k != $r['cust_no']) continue;
$res[] = $r;
}
}
print_r($res);
Array
(
[0] => Array
(
[cust_no] => 237033AW0A
[lotno] => 4409
[part_count] => 300
) [1] => Array
(
[cust_no] => 237033AW0A
[lotno] => 4410
[part_count] => 141
) [2] => Array
(
[cust_no] => 237033RC3A
[lotno] => 4418
[part_count] => 80
))
<?php
foreach($arr as k1=>$v1)
{
$sql2 = "select cust_no,total=SUM(mount)*snp from ".$t." where po_num = '".$stockno."' and cust_no = '".$v1['cust_no']."' group by cust_no,snp";
$result2 = mssql_query($sql2);
$b = array();
while($row2 = mssql_fetch_array($result2))
{
$b[] = $row2;
}
var_export($b);
/*数组b分别对应2笔数据
数据1: array ( 0 => array ( 0 => '237033AW0A', 'cust_no' => '237033AW0A', 1 => 375, 'total' => 375, ),)
数据2: array ( 0 => array ( 0 => '237033RC3A', 'cust_no' => '237033RC3A', 1 => 75, 'total' => 75, ), ))
*/
foreach($b as $var)
{
$num = $var['total'];
foreach($a as $i=>$dest)
{
if($num == 0)
break;
if($dest['cust_no'] != $var['cust_no'])
continue;
if($num >= $dest['part_count'])
{
$num -= $dest['part_count'];
$ress[] = $dest;
$a[$i]['part_count'] = 0;
}
else
{
$dest['part_count'] = $num;
$ress[] = $dest;
$a[$i]['part_count'] -= $num;
$num = 0;
}
}
}
print_r($ress);
/*
目前的结果:
第一笔:
Array
(
[0] => Array
(
[0] => 237033AW0A
[cust_no] => 237033AW0A
[1] => 4409
[lotno] => 4409
[2] => 300
[part_count] => 300
) [1] => Array
(
[0] => 237033AW0A
[cust_no] => 237033AW0A
[1] => 4410
[lotno] => 4410
[2] => 141
[part_count] => 75
) )
第二笔:
Array
(
[0] => Array
(
[0] => 237033AW0A
[cust_no] => 237033AW0A
[1] => 4409
[lotno] => 4409
[2] => 300
[part_count] => 300
) [1] => Array
(
[0] => 237033AW0A
[cust_no] => 237033AW0A
[1] => 4410
[lotno] => 4410
[2] => 141
[part_count] => 75
) )
希望得到的数据:
第一笔:
Array (
[0] => Array (
[cust_no] => 237033AW0A
[lotno] => 4409
[part_count] => 300
)
[1] => Array (
[cust_no] => 237033AW0A
[lotno] => 4410
[part_count] => 75
)
)
第二笔:
Array (
[0] => Array (
[cust_no] => 237033RC3A
[lotno] => 4418
[part_count] => 75
)
)
*/
}
?>
0 =>
array (
'cust_no' => '12653627',
'lotno' => '4069',
'part_count' => 19,
),
1 =>
array (
'cust_no' => '12653627',
'lotno' => '4071',
'part_count' => 146,
),
2 =>
array (
'cust_no' => '12654172',
'lotno' => '4071',
'part_count' => 855,
),
3 =>
array (
'cust_no' => '237033AW0A',
'lotno' => '4409',
'part_count' => 300,
),
4 =>
array (
'cust_no' => '237033AW0A',
'lotno' => '4410',
'part_count' => 141,
),
5 =>
array (
'cust_no' => '237033RC3A',
'lotno' => '4418',
'part_count' => 80,
),
6 =>
array (
'cust_no' => '237033TC0A',
'lotno' => '4401',
'part_count' => 2,
),
7 =>
array (
'cust_no' => '237033TC0A',
'lotno' => '4402',
'part_count' => 1,
),
8 =>
array (
'cust_no' => '237033TC0A',
'lotno' => '4408',
'part_count' => 178,
),
9 =>
array (
'cust_no' => '237033TC0A',
'lotno' => '4409',
'part_count' => 374,
),
);
如果是要对 $b 分组对待,则
foreach($b as $d) {
$res = array();
需要对$a进行减处理,以满足$b的结果。例如:
$ress的结果
Array ( [0] => Array ( [cust_no] => 237033AW0A [lotno] => 4409 [part_count] => 300 ) [1] => Array ([cust_no] => 237033AW0A [lotno] => 4410 [part_count] => 75 ) )
满足$b的结果
array ( 0 => array ( 'cust_no' => '237033AW0A', 'total' => 375, ), )
如果是要对 $b 分组对待,则
foreach($b as $d) {
$res = array();
link和这个问题类似。不过$b变成了多维数组。
0 =>
array (
'cust_no' => '12653627',
'lotno' => '4069',
'part_count' => 19,
),
1 =>
array (
'cust_no' => '12653627',
'lotno' => '4071',
'part_count' => 146,
),
2 =>
array (
'cust_no' => '12654172',
'lotno' => '4071',
'part_count' => 855,
),
3 =>
array (
'cust_no' => '237033AW0A',
'lotno' => '4409',
'part_count' => 300,
),
4 =>
array (
'cust_no' => '237033AW0A',
'lotno' => '4410',
'part_count' => 141,
),
5 =>
array (
'cust_no' => '237033RC3A',
'lotno' => '4418',
'part_count' => 80,
),
6 =>
array (
'cust_no' => '237033TC0A',
'lotno' => '4401',
'part_count' => 2,
),
7 =>
array (
'cust_no' => '237033TC0A',
'lotno' => '4402',
'part_count' => 1,
),
8 =>
array (
'cust_no' => '237033TC0A',
'lotno' => '4408',
'part_count' => 178,
),
9 =>
array (
'cust_no' => '237033TC0A',
'lotno' => '4409',
'part_count' => 374,
),
);
$b = array (
array (
'cust_no' => '237033AW0A',
'total' => 375,
),
array (
'cust_no' => '237033RC3A',
'total' => 75,
),
);
foreach($b as $source) {
do {
$k = 0;
$num = $source['total'];
foreach($a as $i=>$dest) {
if($num == 0) break;
if($dest['cust_no'] != $source['cust_no']) continue;
if($dest['part_count'] == 0) continue;
$k++;
if($num >= $dest['part_count']) {
$num -= $dest['part_count'];
$res[] = $dest;
$a[$i]['part_count'] = 0;
}else {
$dest['part_count'] = $num;
$res[] = $dest;
$a[$i]['part_count'] -= $num;
$num = 0;
}
}
}while($k);
}
var_export($res);
array (
0 =>
array (
'cust_no' => '237033AW0A',
'lotno' => '4409',
'part_count' => 300,
),
1 =>
array (
'cust_no' => '237033AW0A',
'lotno' => '4410',
'part_count' => 75,
),
2 =>
array (
'cust_no' => '237033AW0A',
'lotno' => '4410',
'part_count' => 66,
),
3 =>
array (
'cust_no' => '237033RC3A',
'lotno' => '4418',
'part_count' => 75,
),
4 =>
array (
'cust_no' => '237033RC3A',
'lotno' => '4418',
'part_count' => 5,
),
)
如果只求得这样的结果集:怎么求?array (
0 =>
array (
'cust_no' => '237033AW0A',
'lotno' => '4409',
'part_count' => 300,
),
1 =>
array (
'cust_no' => '237033AW0A',
'lotno' => '4410',
'part_count' => 75,
),
2 =>
array (
'cust_no' => '237033RC3A',
'lotno' => '4418',
'part_count' => 75,
),
)