dsxay48646 2019-02-25 04:42
浏览 62

PHP while循环数组

After I get all the results from my DB, I added some extra data ('Prio')

I used the $_POST method and store the following result in an array:

    array (size=4)
  'gereed' => string 'gereed' (length=6)
  1 => 
    array (size=7)
      'prio' => string '1' (length=1)
      'res' => string '456' (length=3)
      'base' => string '190203' (length=6)
      'lot' => string '101' (length=3)
      'split' => string '0' (length=1)
      'sub' => string '0' (length=1)
      'seq' => string '10' (length=2)
  2 => 
    array (size=7)
      'prio' => string '2' (length=1)
      'res' => string '456' (length=3)
      'base' => string '180676' (length=6)
      'lot' => string '10' (length=2)
      'split' => string '0' (length=1)
      'sub' => string '0' (length=1)
      'seq' => string '30' (length=2)
  3 => 
    array (size=7)
      'prio' => string '3' (length=1)
      'res' => string '456' (length=3)
      'base' => string '180676' (length=6)
      'lot' => string '10' (length=2)
      'split' => string '0' (length=1)
      'sub' => string '0' (length=1)
      'seq' => string '60' (length=2)

Now I have only 3 rows, but it could happen that I have 10 or more rows.

I want to display these data like I did with the while loop. So that the loop will go trough the rows (1, 2, 3, xx) and I can just dispaly them for example like echo $row['prio'];

Maybe it is an easy question, but I'am still learning.

EDIT! At the input part I get the Prio value. I want to update this value at the right row.

UPDATE VMSCHRIP_SIM SET OPERATION_PRIORITY = $_POST['prio'] WHERE BASE = $_POST['base'] AND RESOURCE = $_POST['res'] AND blablabla

something like that...

Here is a part of my code.

if ($result > 1) {
        $i = 1;
        $stmt->execute();
        while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
            $TrCode = transactionCodeDirect($Employee, $row["WORKORDER_BASE_ID"], $row["WORKORDER_LOT_ID"], $row["WORKORDER_SPLIT_ID"], $row["WORKORDER_SUB_ID"], $row["SEQUENCE_NO"], $row["RESOURCE_ID"]);                  
            if ($TrCode <> ""){
                $actief = "<p class=text-success>Actief</p>";
            }else{
                $actief = "<p class=text-warning>Klaar om te starten</p>";
            }
            if($row["DESCRIPTION"] == ""){
                $description = strtok(wo_description($row["WORKORDER_BASE_ID"], $row["WORKORDER_LOT_ID"], $row["WORKORDER_SPLIT_ID"]), '(**');
            }else{
                $description = $row["PART_ID"]." : ".$row["DESCRIPTION"];
            }
            if($row["PREV_OP"] == "" and $row["MAT_REMAINING"] == '0'){
                $row["PREV_OP_COMPLETED_QTY"] = $row["CALC_END_QTY"];
            }
            ?>   
                <a href="#" class="list-group-item"> 
                    <div style="text-align:left">
                        <div class="row">
                            <div class="col-lg-1">  
                                <br>
                                <span class="fa-stack fa-1x">
                                    <i class="fa fa-circle-o fa-stack-2x"></i>
                                    <span  class="fa fa-stack-1x"><?php echo $row["OPERATION_PRIORITY"];?></span>
                                </span>
                            </div>
                            <div class="col-lg-1">  
                                <br>
                                    <input type="text" name="<?php echo $i; ?>[prio]" class="form-control" value="" autofocus placeholder="Prio">
                                    <input type="hidden" name="<?php echo $i; ?>[res]" value="<?php echo $row['RESOURCE_ID'];?>">
                                    <input type="hidden" name="<?php echo $i; ?>[base]" value="<?php echo $row['WORKORDER_BASE_ID'];?>">
                                    <input type="hidden" name="<?php echo $i; ?>[lot]" value="<?php echo $row['WORKORDER_LOT_ID'];?>">
                                    <input type="hidden" name="<?php echo $i; ?>[split]" value="<?php echo $row['WORKORDER_SPLIT_ID'];?>">
                                    <input type="hidden" name="<?php echo $i; ?>[sub]" value="<?php echo $row['WORKORDER_SUB_ID'];?>">
                                    <input type="hidden" name="<?php echo $i; ?>[seq]" value="<?php echo $row['SEQUENCE_NO'];?>">
                            </div>
                            <div class="col-lg-4">  
                                <b><?php echo $row["NAME"];?></b><br>
                                <?php echo $row["WORKORDER_BASE_ID"];?>/<?php echo $row["WORKORDER_LOT_ID"];?>.<?php echo $row["WORKORDER_SPLIT_ID"];?>-<?php echo $row["WORKORDER_SUB_ID"];?>:<?php echo $row["SEQUENCE_NO"];?><br>
                                Vorige bewerking: <?php echo $row["PREV_OP"];?><br>
                            </div>
                            <div class="col-lg-6">                          
                                <?php echo $description;?><br>                                  
                                <?php echo intval($row["COMPLETED_QTY"]);?> / <?php echo intval($row["CALC_END_QTY"]);?> (<?php echo intval($row["PREV_OP_COMPLETED_QTY"]);?>) Stuks
                                <div class="tooltip12"><i class="fa fa-question-circle"></i>
                                    <span class="tooltip12text">Aantal gereed / Totaal (Beschikbaar)</span>
                                </div><br>
                                Volgende bewerking: <?php echo $row["NEXT_OP"];?><br>
                            </div>
                            <div class="col-lg-1">
                                <?php if (transactionCodeDirect($Employee, $row["WORKORDER_BASE_ID"], $row["WORKORDER_LOT_ID"], $row["WORKORDER_SPLIT_ID"], $row["WORKORDER_SUB_ID"], $row["SEQUENCE_NO"], $row["RESOURCE_ID"]) <> ""){ ?>
                                    <i class="fa fa-rotate-right fa-4x" text-center"></i><br><b>Running</b>
                                <?php } ?>  
                            </div>                  
                        </div>
                    </div>
                </a>    
        <?php
        $i++;
        }
    }else{
        echo "Result is niet groter dan 1";
    }
  • 写回答

2条回答 默认 最新

  • dongyu4455 2019-02-25 04:47
    关注

    It could be like this way.

    foreach($_POST as $value){
        if(is_array($value)){
            foreach($value as $key => $val){
                // first iteration
                echo $key; // prio
                echo $val; // 1
    
                // in second iteration, `$val` contains '2'
            }   
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度