dsjws44266 2016-06-03 15:01
浏览 139
已采纳

如何将多个数组合并为一个?

The problem comes when I am echoing more than one order on a page and submitting it. This is my form:

<input name="checkOrder['.($row['ord_no']).'][ord_no]" value="'.($row['ord_no']).'" type="checkbox" class="checkOrder" id="checkOrder">
      <input type="hidden" name="checkOrder['.($row['ord_no']).'][item_seq_no]" value="'.$line_number.'" />
      <input type="hidden" name="checkOrder['.($row['ord_no']).'][item_no]" value="'.$item_number.'" /> 
      <input type="hidden" name="checkOrder['.($row['ord_no']).'][item_desc_1]" value="'.$item_description.'" /></input>

Right now my ouput is this:

Array ( [ord_no] => 1000007 [item_seq_no] => 1 [item_no] => 001 [item_desc_1] => item1 ) 
    Array ( [ord_no] => 1000008 [item_seq_no] => 1 [item_no] => 002 [item_desc_1] => item2 ) 
    Array ( [ord_no] => 1000000 [item_seq_no] => 1 [item_no] => 003 [item_desc_1] => item3 ) 
    Array ( [ord_no] => 1000001 [item_seq_no] => 1 [item_no] => 001 [item_desc_1] => item1 )

I would prefer this:

[checkOrder] => Array
(
        [ord_no] => 1000007
        (
            [item_seq_no] => 1 [item_no] => 001 [item_desc_1] => item1
        )
        [ord_no] => 1000008
        (
            [item_seq_no] => 1 [item_no] => 002 [item_desc_1] => item2
        )
        [ord_no] => 1000000
        (
            [item_seq_no] => 1 [item_no] => 003 [item_desc_1] => item3
        )
        [ord_no] => 1000001
        (
        [item_seq_no] => 1 [item_no] => 001 [item_desc_1] => item1
        )
)

So how do I change my form to create one big array rather than multiple or am I not thinking about this correctly. Right now I am inserting all of these that are checked into a table inside a foreach loop. Then sending one email outside my foreach. It is only inserting the first array order # into the email. When I actually need everyone that was checked. I believe with this other array I have in mind it will fix my problem. If you want more info please let me know.

  • 写回答

1条回答 默认 最新

  • doushi8187 2016-06-03 15:28
    关注

    Change your form to:

      <input name="checkOrder['.($row['ord_no']).'][checked]" value="" type="checkbox" class="checkOrder" id="checkOrder">
      <input type="hidden" name="checkOrder['.($row['ord_no']).'][ord_no]" value="'.($row['ord_no']).'" />
      <input type="hidden" name="checkOrder['.($row['ord_no']).'][item_seq_no]" value="'.$line_number.'" />
      <input type="hidden" name="checkOrder['.($row['ord_no']).'][item_no]" value="'.$item_number.'" /> 
      <input type="hidden" name="checkOrder['.($row['ord_no']).'][item_desc_1]" value="'.$item_description.'" /></input>
    

    if you now var_dump($_POST); you got:

    [checkOrder] => Array
    (
            [1000007] => Array
            (
              [ord_no] => 1000007, [item_seq_no] => 1, [item_no] => 001, [item_desc_1] => item1, [checked]='on'
            )
            [1000008] => Array
            (
              [ord_no] => 1000008, [item_seq_no] => 1, [item_no] => 002, [item_desc_1] => item2, [checked]='on'
            )
            [1000000] => Array
            (
              [ord_no] => 100000, [item_seq_no] => 1, [item_no] => 003,[item_desc_1] => item3, [checked]='on'
            )
            [1000001] => Array
            (
              [ord_no] => 1000001, [item_seq_no] => 1, [item_no] => 001, [item_desc_1] => item1, [checked]='on'
            )
    )
    

    [checked]='on' is only there if you checked that in the Form.

    Hope that helps.

    I need to save just the order numbers outside the foreach

    Then use array_keys($_POST['checkOrder'])and you got the ids.

    But it thing you should use instead of

    <input name="checkOrder['.($row['ord_no']).'][checked]" value="" type="checkbox" class="checkOrder" id="checkOrder">

    this

    <input name="checkedOrders[]" value="'.($row['ord_no'].'" type="checkbox" class="checkOrder" id="checkOrder">

    And then in $_POST['checkedOrders'] are all the ids that where checked in the form.

    The rest will be still the same.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料