Table with select and submit

0

Hello friends I am trying to make a table, for each item in the table it appears a <select> and a submit that will send data via POST , as it is relative how many units will appear can not predict quantities. Unfortunately the way I did any submit sends the last one on the list and not their respective one.

Is it possible to do this? What mistakes did I make?

I'm thinking about redoing all the code since it seems like I did it the wrong way, however I'm a bit confused. Can anyone give me tips.

Here are some snippets of the code.

Body part of the table

   $query="SELECT DISTINCT 'clientes'.'nome', 'ficha_de_moveis'.'id_controle' , 'ficha_de_moveis'.'valor-total-controle','ficha_de_moveis'.'datamontagem', 'ficha_de_moveis'.'status' from 'clientes' join 'ficha_de_moveis' on 'clientes'.'id_cliente' = 'ficha_de_moveis'.'id-cliente'";
    $sql=mysqli_query($conn,$query);
    while($row= mysqli_fetch_array($sql)){
        $numero = $row['id_controle'];
        $cliente = $row['nome'];
        $sobrenome = $row['sobrenome'];
        $valor = $row['valor-total-controle'];
        $data = $row['datamontagem'];
        $data = date("d-m-Y",strtotime(str_replace('/','-',$data)));
        $status = $row['status'];
        echo"   
            <tr>
            <td>$numero</td>
            <td>$loja</td>
            <td>$cliente $sobrenome</td>
            <td>$valor</td>
            <td>$data</td>
            <td>
            <select class='form-control' name='statusm'>
            <option value ='$status'>$status</option>
            <option value=''>----------</option>
            <option value='APROVADO'>APROVADO</option>
            <option value='EXECUTANDO'>EXECUTANDO</option>
            <option value='CONCLUIDO'>CONCLUIDO</option>
            <option value='CANCELADO'>CANCELADO</option>
            </select></td>
            <td>
            <button type='submit' name='mudarStatus' class='btn btn-primary'>
                <i class='glyphicon glyphicon-ok'></i>&ensp;Montar
            </button>
            <a class='btn btn-default btn-sm' href='fichademoveiseditar.php?codigo=$numero&loja=$loja'><span class='glyphicon glyphicon-pencil'></span></a>
            </td>
            </tr>";
    }

Method:

   if(isset($_POST['mudarStatus'])){

                            $mudar_status=$_POST['statusm[]'];
                            echo$mudar_status;
                            echo $controle;
    
asked by anonymous 05.11.2016 / 21:56

1 answer

1
<select class='form-control' name='statusm'>

All your selects have the same name , so only the last one is recognized. You can use name="statusm[]" to send all as an array (which is what your PHP code looks like), or use dynamic names based on each one's ID. There you go.

If you choose the array, in PHP you can only use $_POST['statusm'] .

    
06.11.2016 / 03:12