duanchi8836 2014-04-24 08:41
浏览 14
已采纳

用于进行2 sql更新查询的多维数组

EDIT: i adjusted the array to understand it easyer.

I'm struggling with this a couple of days now and it drives me crazy...

What I basically want is 2 sql update queries that look like this. note that the where statement is from the array.

Code:

"UPDATE gewasregistratie SET lengtegroei= 1, vruchten_geaborteerd= 1, etc.. WHERE kenmerk = 'standaard' AND user_id = ".$user""

"UPDATE gewasregistratie SET lengtegroei= 2, vruchten_geaborteerd= 2, etc.. WHERE kenmerk = 'natugro' AND user_id = ".$user""

I got this multi-level array (its a $_POST["type"] array).

Array
(
    [lengtegroei] => Array
        (
            [standaard] => 1
            [natugro] => 2
        )

    [vruchten_geaborteerd] => Array
        (
            [standaard] => 1
            [natugro] => 2
        )

    [plantbelasting_geteld] => Array
        (
            [standaard] => 1
            [natugro] => 2
        )

    [uitgroeiduur] => Array
        (
            [standaard] => 1
            [natugro] => 2
        )

    [percentage_85ers_en_95ers] => Array
        (
            [standaard] => 1
            [natugro] => 2
        )

    [oogstfrequentie_per_week] => Array
        (
            [standaard] => 1
            [natugro] => 2
        )

    [gezette_vruchten] => Array
        (
            [standaard] => 1
            [natugro] => 2
        )

    [gemiddeld_vruchtgewicht] => Array
        (
            [standaard] => 1
            [natugro] => 2
        )

    [vruchten_geoogst] => Array
        (
            [standaard] => 1
            [natugro] => 2
        )

    [drain] => Array
        (
            [standaard] => 1
            [natugro] => 2
        )

)
  • 写回答

1条回答 默认 最新

  • douxing9567 2014-04-24 09:06
    关注

    do you mean something like this?

    <?php
       $aAll = array();
    
       $aTogather = array(
           'standaard'  => array(),
           'natugro'        => array()
       );
    
       foreach($aPost as $sKey => $mRequest) {
           if(is_array($mRequest)) {
               foreach($mRequest as $sInnKey => $mValue)) {
                   $aTogather[$sInnKey][] = $sKey . ' = ' . '"'.$mValue.'"';
               }
           }
       }
    
       foreach($aTogather as $sKey => $mValue) {
          echo 'UPDATE gewasregistratie SET '.implode(', ', $aTogather[$sKey]).' WHERE kenmerk = "'.$sKey.'" AND user_id = ...';
       }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用