Home >Backend Development >PHP Tutorial >求数组中的对应关系
数组1:Array( [0] => Array ( [cust_no] => 237033AW0A [lotno] => 3207 [lotno_count] => 360 ))数组2:Array([SU13061301033] => Array ( [0] => Array ( [0] => 2013-06-19 09:00:00 [1] => X02B [2] => 237033AW0A [3] => 15 [4] => 14 [5] => 210 ) )[SU13061301032] => Array ( [0] => Array ( [0] => 2013-06-19 09:00:00 [1] => X02B [2] => 237033AW0A [3] => 15 [4] => 17 [5] => 255 ) )[SU13061301037] => Array ( [0] => Array ( [0] => 2013-06-19 09:00:00 [1] => X11Q [2] => 237033AW0A [3] => 15 [4] => 3 [5] => 45 ) [1] => Array ( [0] => 2013-06-19 09:00:00 [1] => X11Q [2] => 237033AW0A [3] => 15 [4] => 2 [5] => 30 ) ))数组3:Array( [0] => SU13061301033 [1] => SU13061301032 [2] => SU13061301037 )
您的 数组1 不就只有一组数据吗?
您的 数组1 不就只有一组数据吗?
这样就无法匹配是吗?数组1和数组3只有对应关系才能求得结果。
如果实在找不到对应关系的话就无法求得需要的值?
对应数组1中的 前210项 这个怎么说?
对应数组1中的 前210项 这个怎么说?
我的意思是数组3中的stockno排在前面的,比如第一项SU13061301033,对应数组2中的值是210。然后用数组1中的总数量去分配210这个值,后面的stockno用总数量-210的结果再去分配下一组值。
PS:可能结果出了问题,所以我要重新查看下sql语句。稍晚再回复您。
如果用排队,倒是可以的
但关键还是在于你数据间的依赖性
如果用排队,倒是可以的
但关键还是在于你数据间的依赖性
好的。明天麻烦你指导下。
还需要你理清思绪路
贴数据时,请帖 var_export 的结果,而不是 print_r 的结果
与人方便,与己方便
结果存储的问题吧
还需要你理清思绪路
贴数据时,请帖 var_export 的结果,而不是 print_r 的结果
与人方便,与己方便
有三张表:kw_manage,vp_barcode_2d_y,stock_detail,分别对应库存,库存对应的批次lotno,出库信息。
库存以packageno为单位入库,通过vp_barcode_2d_y这张表求得入库的packageno对应的批次lotno及数量,cust_no,出库stock_detail含有信息stock_no,对应的关系:一个stock_no对应多个cust_no和对应的数量。
例如下:
SU13061301012(stock_no) A2 2013-06-19 09:00:00 B12D(3) K25B460 237033AW0A(cust_no) 10 15 2013-06-15 15:00:00 2013-06-15 15:30:00SU13061301012(stock_no) A2 2013-06-19 09:00:00 B12D(3) K25B459 237033AW0A(cust_no) 10 15 2013-06-15 15:00:00 2013-06-15 15:30:00
或略具体品种,即一下的讨论值针对单一的品种
入库时有 入库批次和数量 两个属性
出库时有 出库批次和数量 两个属性
你似乎是需要统计:在某个出库批次中都是由哪些入库批次构成的
我理解的对吗?
或略具体品种,即一下的讨论值针对单一的品种
入库时有 入库批次和数量 两个属性
出库时有 出库批次和数量 两个属性
你似乎是需要统计:在某个出库批次中都是由哪些入库批次构成的
我理解的对吗?
是这样。理解正确。
通常情况,我是先正常入库,再根据出库的要求(stock_detail表)用入库的信息来匹配要求。
入库:
CREATE TABLE `kw_manage` ( `ID` int(11) NOT NULL auto_increment, `username` varchar(10) NOT NULL, `rkno` varchar(25) NOT NULL, `packageno` varchar(20) NOT NULL, `type` varchar(20) NOT NULL, `cust_no` varchar(20) NOT NULL, `snp` int(4) NOT NULL, `wh_info` varchar(20) NOT NULL, `date` datetime NOT NULL, PRIMARY KEY (`ID`), KEY `packageno` (`packageno`), KEY `date` (`date`)) ENGINE=MyISAM;INSERT INTO `kw_manage` VALUES (1, 'admin', '201302190001', 'VP3.0 130219001', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-27 10:56:10');INSERT INTO `kw_manage` VALUES (2, 'admin', '201302190001', 'VP3.0 130219002', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-27 10:56:12');INSERT INTO `kw_manage` VALUES (3, 'admin', '201302190001', 'VP3.0 130219003', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-27 10:56:14');INSERT INTO `kw_manage` VALUES (4, 'admin', '201302190001', 'VP3.0 130219004', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:45:20');INSERT INTO `kw_manage` VALUES (5, 'admin', '201302190001', 'VP3.0 130219005', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:45:23');INSERT INTO `kw_manage` VALUES (6, 'admin', '201302190001', 'VP3.0 130219006', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:45:26');INSERT INTO `kw_manage` VALUES (7, 'admin', '201302190001', 'VP3.0 130219007', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:45:28');INSERT INTO `kw_manage` VALUES (8, 'admin', '201302190001', 'VP3.0 130219008', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:45:30');INSERT INTO `kw_manage` VALUES (9, 'admin', '201302190001', 'VP3.0 130219009', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:45:32');INSERT INTO `kw_manage` VALUES (10, 'admin', '201302190001', 'VP3.0 130219010', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:45:35');INSERT INTO `kw_manage` VALUES (11, 'admin', '201302190001', 'VP3.0 130219011', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:45:38');INSERT INTO `kw_manage` VALUES (12, 'admin', '201302190001', 'VP3.0 130219012', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:45:42');INSERT INTO `kw_manage` VALUES (13, 'admin', '201302190002', 'VP3.0 130219013', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:46:06');INSERT INTO `kw_manage` VALUES (14, 'admin', '201302190002', 'VP3.0 130219014', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:46:09');INSERT INTO `kw_manage` VALUES (15, 'admin', '201302190002', 'VP3.0 130219015', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:46:11');INSERT INTO `kw_manage` VALUES (16, 'admin', '201302190002', 'VP3.0 130219016', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:46:13');INSERT INTO `kw_manage` VALUES (17, 'admin', '201302190002', 'VP3.0 130219017', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:46:15');INSERT INTO `kw_manage` VALUES (18, 'admin', '201302190002', 'VP3.0 130219018', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:46:18');INSERT INTO `kw_manage` VALUES (19, 'admin', '201302190002', 'VP3.0 130219019', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:46:19');INSERT INTO `kw_manage` VALUES (20, 'admin', '201302190002', 'VP3.0 130219020', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:46:22');INSERT INTO `kw_manage` VALUES (21, 'admin', '201302190002', 'VP3.0 130219021', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:46:27');INSERT INTO `kw_manage` VALUES (22, 'admin', '201302190002', 'VP3.0 130219022', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:46:30');INSERT INTO `kw_manage` VALUES (23, 'admin', '201302190002', 'VP3.0 130219023', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:46:33');INSERT INTO `kw_manage` VALUES (24, 'admin', '201302190002', 'VP3.0 130219024', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:46:36');INSERT INTO `kw_manage` VALUES (25, 'admin', '201302190023', 'VP3.0 130219048', 'MEC718-000', '23710 JE22A', 15, 'YQ-00-01', '2013-07-08 11:16:57');INSERT INTO `kw_manage` VALUES (26, 'admin', '201302190023', 'VP3.0 130219049', 'MEC718-000', '23710 JE22A', 15, 'YQ-00-01', '2013-07-08 11:17:01');INSERT INTO `kw_manage` VALUES (27, 'admin', '201302190023', 'VP3.0 130219050', 'MEC718-000', '23710 JE22A', 15, 'YQ-00-01', '2013-07-08 11:17:08');INSERT INTO `kw_manage` VALUES (28, 'admin', '201302190023', 'VP3.0 130219051', 'MEC718-000', '23710 JE22A', 15, 'YQ-00-01', '2013-07-08 11:17:13');INSERT INTO `kw_manage` VALUES (29, 'admin', '201302190023', 'VP3.0 130219052', 'MEC718-000', '23710 JE22A', 15, 'YQ-00-01', '2013-07-08 11:17:23');INSERT INTO `kw_manage` VALUES (30, 'admin', '201302190023', 'VP3.0 130219053', 'MEC718-000', '23710 JE22A', 15, 'YQ-00-01', '2013-07-08 11:17:30');INSERT INTO `kw_manage` VALUES (31, 'admin', '201302190023', 'VP3.0 130219054', 'MEC718-000', '23710 JE22A', 15, 'YQ-00-01', '2013-07-08 11:17:39');INSERT INTO `kw_manage` VALUES (32, 'admin', '201302190023', 'VP3.0 130219055', 'MEC718-000', '23710 JE22A', 15, 'YQ-00-01', '2013-07-08 11:17:54');
本着先进先出的原则,出库过程是这样的:
出库数量已知
遍历入库表,从 出库数量 中扣除当前入库批次的数量,直到 出库数量 小于等于 0
若 出库数量 为负,则将其绝对值加回去
本着先进先出的原则,出库过程是这样的:
出库数量已知
遍历入库表,从 出库数量 中扣除当前入库批次的数量,直到 出库数量 小于等于 0
若 出库数量 为负,则将其绝对值加回去
出库:
$sql4 = "select arr_time,c_type,cust_no,snp,mount,mount*snp as m_total,stock_no from `".$t."` where stock_no = '".$stockno[$j-1]."'";// echo $sql4.'<br />'; $result4 = mysql_query($sql4); $ar = array(); while($var = mysql_fetch_array($result4,MYSQL_NUM)) { $ar[] = $var; } $a = array(); foreach ($ar as $item) { $key = array_pop($item); if (! isset($a[$key])) $a[$key] = array(); $a[$key][] = $item;}var_xeport的结果:array ( 'SU13061301033' => array ( 0 => array ( 0 => '2013-06-19 09:00:00', 1 => 'X02B', 2 => '237033AW0A', 3 => '15', 4 => '14', 5 => '210', ), ), )
$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);// print_r($res); $arrs = array(); foreach($res as $v2) { $arrs[] = $v2; } var_export($arrs);结果:array ( 0 => array ( 'lotno' => '3207', 'count' => 360, ), )//这个结果是入库的总数量,是否要求得分别的数量?
你贴 入库 的代码是什么意思?
你贴 入库 的代码是什么意思?
不需要知道入库总量?如何去判定入库的批次已匹配过,不回出现在其他的stock_no的结果中?
你给的数据和代码不配套
Unknown column 'arr_time' in 'field list'
刚才出库的数据没给全,贴不下了。现在补上。
CREATE TABLE `stock_detail` ( `ID` int(11) NOT NULL auto_increment,`stock_no` varchar(20) NOT NULL,`adress` varchar(10) NOT NULL,`arr_time` datetime NOT NULL,`c_type` varchar(20) NOT NULL,`pu_no` varchar(20) NOT NULL,`cust_no` varchar(20) NOT NULL,`mount` int(10) NOT NULL,`snp` int(10) NOT NULL,`c1_time` datetime NOT NULL,`c2_time` datetime NOT NULL, PRIMARY KEY (`ID`)) ENGINE=MyISAM;INSERT INTO `stock_detail` VALUES (42, 'SU13061301029', 'B', '2013-06-20 22:00:00', 'P32L', 'K25K498', '310F61VA5A', 9, 16, '2013-06-15 15:00:00', '2013-06-15 15:30:00');INSERT INTO `stock_detail` VALUES (43, 'SU13061301029', 'B', '2013-06-20 22:00:00', 'P32L', 'K25K497', '310F61VA5A', 10, 16, '2013-06-15 15:00:00', '2013-06-15 15:30:00');INSERT INTO `stock_detail` VALUES (44, 'SU13061301031', 'A1', '2013-06-20 09:00:00', 'X02B', 'K25B418', '237033AW0A', 14, 15, '2013-06-15 15:00:00', '2013-06-15 15:30:00');INSERT INTO `stock_detail` VALUES (45, 'SU13061301030', 'A1', '2013-06-20 09:00:00', 'X02B', 'K25B417', '237033AW0A', 17, 15, '2013-06-15 15:00:00', '2013-06-15 15:30:00');INSERT INTO `stock_detail` VALUES (46, 'SU13061301033', 'A1', '2013-06-19 09:00:00', 'X02B', 'K25B416', '237033AW0A', 14, 15, '2013-06-15 15:00:00', '2013-06-15 15:30:00');INSERT INTO `stock_detail` VALUES (47, 'SU13061301032', 'A1', '2013-06-19 09:00:00', 'X02B', 'K25B415', '237033AW0A', 17, 15, '2013-06-15 15:00:00', '2013-06-15 15:30:00');INSERT INTO `stock_detail` VALUES (48, 'SU13061301034', 'A1', '2013-06-19 09:00:00', 'X11Q', 'K25B407', '237033AW0A', 6, 15, '2013-06-15 15:00:00', '2013-06-15 15:30:00');INSERT INTO `stock_detail` VALUES (49, 'SU13061301034', 'A1', '2013-06-19 09:00:00', 'X11Q', 'K25B408', '237033AW0A', 9, 15, '2013-06-15 15:00:00', '2013-06-15 15:30:00');INSERT INTO `stock_detail` VALUES (50, 'SU13061301035', 'A1', '2013-06-20 09:00:00', 'X11Q', 'K25B409', '237033AW0A', 7, 15, '2013-06-15 15:00:00', '2013-06-15 15:30:00');INSERT INTO `stock_detail` VALUES (51, 'SU13061301035', 'A1', '2013-06-20 09:00:00', 'X11Q', 'K25B410', '237033AW0A', 9, 15, '2013-06-15 15:00:00', '2013-06-15 15:30:00');INSERT INTO `stock_detail` VALUES (52, 'SU13061301036', 'A1', '2013-06-20 09:00:00', 'X11Q', 'K25B434', '237033AW0A', 3, 15, '2013-06-15 15:00:00', '2013-06-15 15:30:00');INSERT INTO `stock_detail` VALUES (53, 'SU13061301036', 'A1', '2013-06-20 09:00:00', 'X11Q', 'K25B433', '237033AW0A', 2, 15, '2013-06-15 15:00:00', '2013-06-15 15:30:00');INSERT INTO `stock_detail` VALUES (54, 'SU13061301037', 'A1', '2013-06-19 09:00:00', 'X11Q', 'K25B431', '237033AW0A', 3, 15, '2013-06-15 15:00:00', '2013-06-15 15:30:00');INSERT INTO `stock_detail` VALUES (55, 'SU13061301037', 'A1', '2013-06-19 09:00:00', 'X11Q', 'K25B432', '237033AW0A', 2, 15, '2013-06-15 15:00:00', '2013-06-15 15:30:00');INSERT INTO `stock_detail` VALUES (56, 'SU13061500001', 'A1', '2013-06-20 09:00:00', 'L11K', 'C6E0085', '23703EX80A', 2, 15, '2013-06-15 15:00:00', '2013-06-15 15:30:00');INSERT INTO `stock_detail` VALUES (57, 'SU13061500002', 'A1', '2013-06-20 09:00:00', 'X11Q', 'C6E0084', '237033AW0A', 1, 15, '2013-06-15 15:00:00', '2013-06-15 15:30:00');
你给的数据和代码不配套
Unknown column 'arr_time' in 'field list'
烦见20#
本着先进先出的原则,出库过程是这样的:
出库数量已知
遍历入库表,从 出库数量 中扣除当前入库批次的数量,直到 出库数量 小于等于 0
若 出库数量 为负,则将其绝对值加回去
烦请举个例子吧,对这句话的意思不理解。
遍历入库表,从 出库数量 中扣除当前入库批次的数量