0

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
  • Could you explain your question better please? From your description it is hard to understand what you are actually asking. Commented Apr 24, 2014 at 8:54

1 Answer 1

1

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 = ...';
   }
?>
Sign up to request clarification or add additional context in comments.

6 Comments

Not really, all im looking for is 2 sql queries, 1 for WHERE kenmerk = "standaard" and 1 for WHERE kenmerk = "natugro"
I eddited my question to make it more understandable
Great ! this works. Thanks alot mate !! i dont really understand what u did, could u explain it a bit pls ?
Which part you would like me to explain? The most important, you know how foreach works yes?
Yes i do understand foreach. the part i dont understand is why u make $atogather array and then standaard and natugro array inside
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.