Change data using Checkbox - Php + Mysql

Asked

Viewed 396 times

0

Hello, I am mounting an internal order system and would like to include status/situation steps, I am trying to do this in bulk using checkbox.

Basically I want to select x number of items on a list, and transport them to another list. My difficulty is being in picking up part of the items.

My Example: I have 5 items on order, I will buy only 2 today and 3 next week.

Form: gerar_compra.php

Query to return open orders:

...

$resultado=mysqli_query($conn, "
        SELECT pedidos.id as id, data_pedido, produtos_c.nome as produto, produtos_c.unidade as unidade, qtde, data_aplicacao, local_aplicacao, solicitante, situacao
        FROM pedidos
        INNER JOIN produtos_c
        ON pedidos.produto = produtos_c.id
        ORDER BY 'id'");
        
        $linhas=mysqli_num_rows($resultado);

...

List view (gerar_compra.php)

<div class="form-control input-sm">

<form id="select" method="POST">
<table class="table table-hover">
    <thead>
      <tr>
        <th>Id</th>
        <th>Data</th>
        <th>Produto</th>
        <th>Unidade</th>
        <th>Quantidade</th>
        <th>Data Aplicação</th>
        <th>Local Aplicação</th>
        <th>Solicitante</th>
        <th>Situação</th>
                    
      </tr>
    </thead>
    <tbody>

        <div>
        <?php 
            while($linhas = mysqli_fetch_array($resultado)){
                echo "<tr>";
                    echo "<td>".$linhas['id']."</td>";
                    echo "<td>".date_format(New DateTime($linhas['data_pedido']), 'd/m/Y H:i:s')."</td>";
                    echo "<td>".$linhas['produto']."</td>";
                    echo "<td>".$linhas['unidade']."</td>";
                    echo "<td>".number_format($linhas['qtde'], 2,',','.')."</td>";
                    echo "<td>".date_format(New DateTime($linhas['data_aplicacao']), 'd/m/Y')."</td>";
                    echo "<td>".$linhas['local_aplicacao']."</td>";
                    echo "<td>".$linhas['solicitante']."</td>";
                    echo "<td>".$linhas['situacao']."</td>";
                                            
        ?>
                <td>
                <input type="checkbox" name="check[]" value="<?php echo $linhas['id'];?>">
                                                    
                <?php
                echo "</tr>";
                }
                ?>
        </div>
        
        
        <div class="form-group">
            <div class="col-sm-offset-0 col-sm-10">
              <button type="submit" name="enviar" class="btn btn-default">Processar Compra</button>
            </div>
        </div>
    
                
    </tbody>
                
        
</form>

However I am not able to get the data of the line, I am tempted to mark the options, (then I will use the update in the field "situation") and using "SELECT" to create a new form with the same structure above, but only with the items marked.

<?php    

            $selecao = "";
            if(isset($_POST["check"])){echo "Os modulos Escolhidos foram:<BR>";
            // Faz loop pelo array dos numeros

            foreach($_POST["check"] as $modulo){
                echo " - " . $modulo .  "<BR>";
            $selecao .= $modulo;
            }
            }
            else{echo "Você não escolheu modulos!<br>";
            }
            echo $selecao. "\n"."echo selecao<br>";
            echo $selecao. "\n"."echo modulo<br>";
            
            var_dump($modulo);
            
            $comprado = mysqli_query($conn, "

            SELECT pedidos.id as id, data_pedido, produtos_c.nome as produto, produtos_c.unidade as unidade, qtde, data_aplicacao, local_aplicacao, solicitante, situacao
            FROM pedidos
            INNER JOIN produtos_c
            ON pedidos.produto = produtos_c.id
            WHERE pedidos.id = '$modulo'
            
            ");
            
            $comprados = mysqli_num_rows($comprado);
            
            ?>

I think my problem is the line in the query "WHERE orders.id = '$module'" does not carry all marked items, only the last.

If anyone can help, I believe that for the more experienced of hitting the eye will already have a solution or indicate where I should research.

Thank you.

  • You could put here the result of the line var_dump($modulo) ? &#As far as I can tell, inside the foreach of $modulo, on the line $selecao .= $modulo you are concatenating all modules without comma or space. This is probably making it not find any results in the database

  • These are the 4-click results. " The Chosen modules were: -1 -2 -3 -4 1234 echo select 1234 echo module string(1) "4"

No answers

Browser other questions tagged

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