Checkbox inside of While

Asked

Viewed 145 times

0

I am in need of replicating this table from the company’s ERP system to the WEB system.

inserir a descrição da imagem aqui

But using the code below the image I have the value of the variables that are 0 and 1.

inserir a descrição da imagem aqui

<table border="2">
          <tr>
              <th>  Id  </th>
              <th> Tipo </th>
              <th> Descrição </th>
              <th> NFe </th>
              <th> Bonificada </th>
              <th> Quebra </th>
              <th> Falha na Operação </th>
              <th> Transferência </th>
              <th> Movimenta Estoque </th>
              <th> Valida Preço </th>
              <th> Gera Entrada </th>
          </tr>
      <?php
            include ("conn.php");

              $result = "SELECT * FROM tipofat ORDER BY id";
              $resultado = mysqli_query($conn, $result);


              while ($row = mysqli_fetch_assoc($resultado)){

                  echo "<tr class='btn-default'>";
                      echo "<td class='get-func'>". $row['id'] ."</td>";
                      echo "<td class= 'get-cadfunc'>". $row['tp_faturamento'] ."</td>";
                      echo "<td class= 'get-cadfunc'>". $row['descricao'] ."</td>";
                      echo "<td class= 'get-cadfunc'>". $row['nfe'] ."</td>"; 
                      echo "<td class= 'get-cadfunc'>". $row['bnf_com_nota'] ."</td>";
                      echo "<td class= 'get-cadfunc'>". $row['bnf_sem_nota'] ."</td>";
                      echo "<td class= 'get-cadfunc'>". $row['falha_operacao'] ."</td>";
                      echo "<td class= 'get-cadfunc'>". $row['transferencia'] ."</td>";
                      echo "<td class= 'get-cadfunc'>". $row['mov_estoque'] ."</td>";
                      echo "<td class= 'get-cadfunc'>". $row['valida_preco'] ."</td>";
                      echo "<td class= 'get-cadfunc'>". $row['gera_entrada'] ."</td>";
                  echo "</tr>";
              }
          ?>
  </table>

I have tried thousands of ways to make instead of the values come checkox changing my <td></td> , but unsuccessful because, the checkbox are inserted in the places of the numbers but do not come filled/ checked, I will leave an example below the attempts

echo '<td><input type="checkbox" name="nfe['.$row['nfe'].']" value="'. $row['nfe'] .' onclick="return false;" "</td>';
echo '<td><input type="checkbox" '. $row['nfe'] .' onclick="return false;" "</td>';
  • 2

    tries to put an if: echo "<td class= 'get-cadfunc'><input type='checkbox' name='nfe' value='nfe'" . if($Row['nfe'] == 1) "checked" ." </td>";

  • tried but it didn’t work

1 answer

1


<table border="2">
          <tr>
              <th>  Id  </th>
              <th> Tipo </th>
              <th> Descrição </th>
              <th> NFe </th>
              <th> Bonificada </th>
              <th> Quebra </th>
              <th> Falha na Operação </th>
              <th> Transferência </th>
              <th> Movimenta Estoque </th>
              <th> Valida Preço </th>
              <th> Gera Entrada </th>
          </tr>
      <?php
            include ("conn.php");

              $result = "SELECT * FROM tipofat ORDER BY id";
              $resultado = mysqli_query($conn, $result);


              while ($row = mysqli_fetch_assoc($resultado)){

                  echo "<tr class='btn-default'>";
                      echo "<td class='get-func'>". $row['id'] ."</td>";
                      echo "<td class= 'get-cadfunc'>". $row['tp_faturamento'] ."</td>";
                      echo "<td class= 'get-cadfunc'>". $row['descricao'] ."</td>";
                      echo "<td class= 'get-cadfunc'><input type=\"checkbox\"". (($row['nfe'] == 1) ? " checked" : "")." disabled></td>"; 
                      echo "<td class= 'get-cadfunc'><input type=\"checkbox\"". (($row['bnf_com_nota'] == 1) ? " checked" : "")." disabled></td>";
                      echo "<td class= 'get-cadfunc'><input type=\"checkbox\"". (($row['bnf_sem_nota'] == 1) ? " checked" : "")." disabled></td>";
                      echo "<td class= 'get-cadfunc'><input type=\"checkbox\"". (($row['falha_operacao'] == 1) ? " checked" : "")." disabled></td>";
                      echo "<td class= 'get-cadfunc'><input type=\"checkbox\"". (($row['transferencia'] == 1) ? " checked" : "")." disabled></td>";
                      echo "<td class= 'get-cadfunc'><input type=\"checkbox\"". (($row['mov_estoque'] == 1) ? " checked" : "")." disabled></td>";
                      echo "<td class= 'get-cadfunc'><input type=\"checkbox\"". (($row['valida_preco'] == 1) ? " checked" : "")." disabled></td>";
                      echo "<td class= 'get-cadfunc'><input type=\"checkbox\"". (($row['gera_entrada'] == 1) ? " checked" : "")." disabled></td>";
                  echo "</tr>";
              }
          ?>
  </table>
  • thanks just what I wanted, but have as I make them get disabled too ? I tried with disabled and did not succeed

  • I changed the answer, it’s with disabled even, check if you had put it the right way.

  • Thank you, I typed wrong even, I put disabeld rsrs but it was just as you reported, thanks again for sharing your wisdom

Browser other questions tagged

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