dongli9894 2016-07-11 18:27
浏览 163
已采纳

如何为订单中的每个框创建唯一编号

The issue is not how I am generating the number, that is working fine for a different app I have. The issue is counting the total number of boxes and iterating through a forloop that many times. Right now I am multiplying box_ct * qty_ord to get the total boxes. BTW, I am still trying to understand everything I can do with foreach and for loops, so if anyone has a better idea, Great. CLARIFICATION: I am searching the database by order number and pulling back qty_ord, box_ct, and item_no for each. On some orders there is more than one item. So for each item I need to multiply qty_ord by box_ct = count and for that specific item I need to iterate through the loop based on what my count is.Right now if I remove the foreach and hardcode the for loop count variable it works fine. Any ideas on what is wrong with my foreach?

qty_ord | box_ct | item_no
------------------------
1          2        10001
3          3        10002
2          1        10003
2          3        10004
2          6        10005

Below is my code.

$sql ="SELECT imitmidx_sql.box_ct, oeordlin_sql.item_no, oeordlin_sql.qty_ord
                    FROM imitmidx_sql 
                    JOIN oeordlin_sql ON oeordlin_sql.item_no = imitmidx_sql.item_no WHERE ord_no ='$orderNum'";

            $query = odbc_exec($conn, $sql);

            $row7 = odbc_fetch_array($query);

            foreach($row7['item_no'] as $item){
                $count = $row7['qty_ord'] * $row7['box_ct'];

                    for($counter = 0; $counter <= $count; $counter++){
                        //GRAB NUMBER FROM FILE 
                        $sscc = file_get_contents("ucc128.txt");
                        //INCREMENT NUMBER
                        $sscc++;
                        //PUT THE NUMBER BACK IN FILE
                        $sscc = file_put_contents("ucc128.txt", $sscc);
                        //COMBINE STATIC NUMBER AND NUMBER FROM FILE 
                        $ssccnumber = "00950000".$sscc;
                        //CREATE CHECK DIGIT MATH
                        $ssccnumArray = str_split((string)$ssccnumber);
                        $ssccstep1 = array_combine(range(1, count($ssccnumArray)), $ssccnumArray);

                        $ssccstep2 = 0;
                        $ssccstep4 = 0;
                        foreach($ssccnumArray as $k => $v){
                            if($k%2){
                                $ssccstep2 += (int)$v;
                            }else{
                                $ssccstep4 += (int)$v;
                            }
                        }

                        $ssccstep3 = (int)$ssccstep2 * 3;
                        $ssccstep5 = (int)$ssccstep3 + (int)$step4;
                        $ssccCheckDigit = (ceil($ssccstep5 / 10) * 10) - $ssccstep5;
                        //END CREATE CHECK DIGIT
                        //CONCATENATE FULL NUMBER    
                        $sscc1 = $ssccnumber.$ssccCheckDigit;

                        $sql = "INSERT INTO ucc128 (sscc, ord_no) VALUES ('$sscc1' ,'$orderNum')";
                        #echo $sql.'<br />';
                        odbc_exec($connPRONUMBER, $sql);
                }
            }
  • 写回答

2条回答 默认 最新

  • drbvm26000 2016-07-12 13:49
    关注

    My foreach was not working, so what I did instead was get the sum using my SQL query.

    SELECT SUM(imitmidx_sql.box_ct * oeordlin_sql.qty_ord) AS total
                        FROM imitmidx_sql 
                        JOIN oeordlin_sql ON oeordlin_sql.item_no = imitmidx_sql.item_no WHERE ord_no ='$orderNum'
    

    I was then able to ouput it and save $row7['total'] to the variable $count.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)