Create a new array with information from an Array sends via POST

0

I can not make a batch change of the information displayed through While .

What I want to do is to create a new Array with the information I am sending via POST , that is, I send the information via POST , which creates Array below.

Array
(
    [exibirconcessao] => Array
        (
            [0] => Array
                (
                    [id] => 91
                    [field3] => 2222
                    [field2] => 3
                    [field4] => 2016-04-15 15:38:24
                    [field5] => REVENDA
                    [field12] => 1111
                    [field13] => 11111
                    [field61] => CRISTIANO
                    [field62] => DUTRA IGLESIAS
                    [field7] => RS1001-001
                    [field8] => RS Sede
                    [field14] => 1
                    [field9] => 4
                    [field10] => 1
                    [field16] => criado usuario
                    [numerochamado] => 
                    [novostatus] => 
                    [observacoes] => 
                )

            [1] => Array
                (
                    [id] => 92
                    [field3] => 
                    [field2] => 1
                    [field4] => 2016-04-15 15:38:24
                    [field5] => REVENDA
                    [field12] => 
                    [field13] => 
                    [field61] => CRISTIANO
                    [field62] => DUTRA IGLESIAS
                    [field7] => RS1001-001
                    [field8] => RS Sede
                    [field14] => 2
                    [field9] => 4
                    [field10] => 1
                    [field16] => criado usuario
                    [numerochamado] => 
                    [novostatus] => 
                    [observacoes] => 
                )

            [2] => Array
                (
                    [id] => 93
                    [field3] => 
                    [field2] => 1
                    [field4] => 2016-04-15 15:38:24
                    [field5] => REVENDA
                    [field12] => 
                    [field13] => 
                    [field61] => CRISTIANO
                    [field62] => DUTRA IGLESIAS
                    [field7] => RS1001-001
                    [field8] => RS Sede
                    [field14] => 3
                    [field9] => 4
                    [field10] => 1
                    [field16] => criado usuario
                    [numerochamado] => 
                    [novostatus] => 
                    [observacoes] => 
                )

        )

)

I want to create a new Array by adding information in the last 3 fields: [numerochamado] , [novostatus] and [observacoes] , this information will be provided through the Batch Change field according to the system image:

This is the Array sent by the batch change field:

Array
(
    [loteconcessao] => Array
        (
            ['numerochamado'] => 12345
            ['novostatus'] => Concluido
            ['observacoes'] => Teste
        )
)
    
asked by anonymous 18.04.2016 / 20:06

1 answer

1

While I was waiting for Response, I was able to develop a method to solve my difficulty, but as I commented to @DanielOmine, the tip that he passed also works, so this conclusion I came to is only a different way of answering the same doubt: p>

code.php

  

This is a simplified form of how I got the answer.

$lista1 = array();
$lista1[0] = 'Pão';
$lista1[1] = 'Ovos';
$lista1[2] = 'Carne';
$lista1[3] = 'Macarrão';
$lista1[4] = '';
$lista1[5] = '';
$lista1[6] = '';

$lista2 = array();
$lista2[0] = 'item 1';
$lista2[1] = 'item 2';
$lista2[2] = 'item 3';

$lista3 = array();
$lista3[0] = $lista1[0];
$lista3[1] = $lista1[1];
$lista3[2] = $lista1[2];
$lista3[3] = $lista1[3];
$lista3[4] = $lista2[0];
$lista3[5] = $lista2[1];
$lista3[6] = $lista2[2];


echo "<pre>";
print_r($lista1);
echo "<br>";
print_r($lista2);
echo "<br>";
print_r($lista3);
echo "</pre>";

Result

Array
(
    [0] => Pão
    [1] => Ovos
    [2] => Carne
    [3] => Macarrão
    [4] => 
    [5] => 
    [6] => 
)

Array
(
    [0] => item 1
    [1] => item 2
    [2] => item 3
)

Array
(
    [0] => Pão
    [1] => Ovos
    [2] => Carne
    [3] => Macarrão
    [4] => item 1
    [5] => item 2
    [6] => item 3
)
  

And this was the method I put on my system:

for ($i = 0; $i < count($_POST[exibirconcessao]); $i++){

    $POST_CON[$i][] = $_POST[exibirconcessao][$i][id];
    $POST_CON[$i][] = $_POST[exibirconcessao][$i][field3];
    $POST_CON[$i][] = $_POST[exibirconcessao][$i][field2];
    $POST_CON[$i][] = $_POST[exibirconcessao][$i][field4];
    $POST_CON[$i][] = $_POST[exibirconcessao][$i][field5];
    $POST_CON[$i][] = $_POST[exibirconcessao][$i][field12];
    $POST_CON[$i][] = $_POST[exibirconcessao][$i][field13];
    $POST_CON[$i][] = $_POST[exibirconcessao][$i][field62];
    $POST_CON[$i][] = $_POST[exibirconcessao][$i][field61];
    $POST_CON[$i][] = $_POST[exibirconcessao][$i][field7];
    $POST_CON[$i][] = $_POST[exibirconcessao][$i][field8];
    $POST_CON[$i][] = $_POST[exibirconcessao][$i][field14];
    $POST_CON[$i][] = $_POST[exibirconcessao][$i][field9];
    $POST_CON[$i][] = $_POST[exibirconcessao][$i][field10];
    $POST_CON[$i][] = $_POST[exibirconcessao][$i][field16];
    $POST_CON[$i][] = $_POST[exibirconcessao][$i][field15];
    $POST_CON[$i][] = $_POST[loteconcessao][lc][numerochamado];
    $POST_CON[$i][] = $_POST[loteconcessao][lc][novostatus];
    $POST_CON[$i][] = $_POST[loteconcessao][lc][observacoes];

}

$data = $POST_CON; 

    foreach ($data as $key => $value) {

if (isset($value[0]) && !empty($value[0])) {

    if($value[2] != 3){

    $where              = Array();
    $where2         = Array();
    $id             = $value[0];
    $numerochamado      = $value[1];
    $numerochamadolote  = $value[15];
    $novostatus     = $value[2];
    $novostatuslote = $value[16];
    $matricula          = $value[5];
    $login              = $value[6];
    $observacoes        = $value[14];
    $observacoeslote    = $value[17];
    $cpf                = $value[15];

    if(     $numerochamado      ){ $where[]  = "'hcm_chamado' = '{$numerochamado}'"; }
    elseif( $numerochamadolote  ){ $where[]  = "'hcm_chamado' = '{$numerochamadolote}'"; }
    if(     $novostatuslote ){ $where[]  = "'hcm_statusinterno' = '{$novostatuslote}'"; }
    elseif( $novostatus     ){ $where[]  = "'hcm_statusinterno' = '{$novostatus}'"; }
    if(     $matricula          ){ $where[]  = "'hcm_matricula' = '{$matricula}'"; }
    if(     $login              ){ $where[]  = "'hcm_login' = '{$login}'"; }
    if(     $observacoeslote    ){ $where[]  = "'hcm_sd_obs' = '{$observacoeslote}'"; }
    elseif( $observacoes        ){ $where[]  = "'hcm_sd_obs' = '{$observacoes}'"; }
    if(     $id             ){ $where2[] = "'hcm_id' = '{$id}'"; }

    $sql = "UPDATE 'ac_hcm_concessao' SET ";
    if( sizeof( $where ) )
        $sql .= implode( ', ',$where ).' WHERE '. implode($where2);
        $query = $mysqli->query($sql);



    }
  }
}
    
19.04.2016 / 17:13