Table with select and Submit

Asked

Viewed 94 times

0

Hello friends I’m trying to make a table, being for each table item appears a <select> and a submit that will send data via POST, as it is relative how many units will appear it is not possible to predict quantities. Unfortunately the way I did any Ubmit sends the last of the list and not its respective.

Is it possible to do this action? What mistakes have I made?

I’m thinking about redoing all the code since it seems I did it wrong, but I’m a little confused.Can someone give me tips.

Follow some excerpts from 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;

1 answer

1


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

All your selects have the same name, so only the latter is recognized. You can use name="statusm[]" to send them all as an array (which is what it looks like your PHP code is searching for) or use dynamic names based on each one’s identification. There goes your preference.

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

Browser other questions tagged

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