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

Asked

Viewed 73 times

0

I cannot make a batch change to the information displayed through While.

What I want to do is create a new Array with the information I am sending via POST, that is, send the information via POST, that creates the Array down 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:

inserir a descrição da imagem aqui

This is the Array sent by the batch change field:

Array
(
    [loteconcessao] => Array
        (
            ['numerochamado'] => 12345
            ['novostatus'] => Concluido
            ['observacoes'] => Teste
        )
)
  • Do you want to create a new array or simply insert this 3 data into the other array? Technically you don’t need to create a new array (unless you want to).

  • If the intention is only to set a value for a specific key in a multidimensional array of varied or fixed size and output, this can be useful: http://answall.com/a/123596/4793

  • The intention is just to create a unique array to insert the information in the BD @Fleuquerlima

  • @Danielomine by the tests I performed with your tip, it worked perfectly, but I ended up creating another method while waiting for an answer, I will share what I discovered as an answer to my own question, but I will study your code to understand exactly what was done in the function, thanks for the help!

  • Do the data contained in "[displarconcessao][0]" correspond to the data contained in [loteconcessao][0]" ? How do you identify that these data are matching?

1 answer

1

While waiting for Reply, I was able to develop a method to solve my difficulty, but as I commented to @Danielomine the tip he passed also works, so this conclusion I reached is only a different way to answer the same doubt:

php code.

This is a simplified way of how I arrived at 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>";

Upshot

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 is the method I put into 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);



    }
  }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.