Jump to content
Fórum Script Brasil
  • 0

ARRAY PHP


Guest

Question

Como faço pra criar um array, pegando os valor de uma lista conforme mostrado no código abaixo: 

<div class="row mt-5">
                            <div class="col-xl-2 col-lg-2 col-md-2 col-sm-6">
                                <div class="form-group ">
                                    <label for="produto">Nome do Produto</label>
                                    <select class="form-control " id="txtproduto" >
                                        <?php
                                                                            
                                            $query = "SELECT * FROM produto ORDER BY produto asc";
                                            $result = mysqli_query($conexao$query);
 
                                            if(count($result)){
                                            while($res = mysqli_fetch_array($result)){
                                        ?>                                             
                                        <option value="<?php echo $res['produto']; ?>"><?php echo $res['produto']; ?></option> 
                                        <?php      
                                            }
                                            }
                                        ?>
                                    </select>               
                                </div>
                            </div>
                            <div class="col-xl-2 col-lg-2 col-md-2 col-sm-6">
                                <div class="form-group ">
                                    <label for="descricao"> Descrição </label>
                                    <input type="text" class="form-control mr-2" id="txtdescricao" name="descricao" placeholder="Descrição" required >
                                    
                                </div>
                            </div>
                            <div class="col-xl-2 col-lg-2 col-md-2 col-sm-6 ml-2">
                                <div class="form-group ">
                                    <label for="qtdentrada"> Quantidade </label>
                                    <input type="number" class="form-control mr-2" id="txtqtdentrada" placeholder="Quantidade" required >
                                </div>
                            </div> 
                            <div class="col-xl-2 col-lg-2 col-md-2 col-sm-6">
                                <div class="form-group" style="margin-left: 9px;">
                                    <label for="custouni"> Custo Unitário </label>
                                    <input type="text" class="form-control mr-2 money" id="txtcustouni"  placeholder="Custo Unitário" required >
                                </div>
                            </div>
                            <div class="col-xl-2 col-lg-2 col-md-2 col-sm-6 ml-2">
                                <div class="form-group ">
                                    <label for="precovenda"> Preço de Venda </label>
                                    <input type="text" class="form-control mr-2 money" id="txtprecovenda"  placeholder="Preço de Venda" required >
                                </div>
                            </div>
                            <div class="col-xl-1 col-lg-2 col-md-2 col-sm-6">
                                <div class="form-group ">
                                    <a type"button" class="editar btn btn-success mt-4 ml-3" onclick"cadEstoque(txtproduto.valuetxtdescricao.valuetxtqtdentrada.valuetxtcustouni.valuetxtprecovenda.value)"><i class="fas fa-plus-circle"></i></a>
                                </div> 
                            </div> 
                        </div>

Esse é código da minha tabela 

 <div class="table-responsive-sm">                
                <table class="table" id="registroTabela">
                    <thead>
                        <tr>
                            <th scope="col">Nome do Produto</th>
                            <th scope="col">ID Estoque</th>
                            <th scope="col">Quantidade</th>
                            <th scope="col">Custo Unitário</th>
                            <th scope="col">Preço de Venda</th>
                        </tr> 
                        <tbody id="listaRegistro">
                        </tbody>
                    </thead>
                   
                </table>
            </div>

Tenho um script como mostra no código abaixo, que quando clico cadEstoque vai criando uma lista do produto com base as informações inserida no formulário

<script>
 
            let fields = [
                    'produto',
                    'descricao',
                    'qtdentrada',
                    'custouni',
                    'precovenda',
                ]
                tabela = document.getElementById('registroTabela');
 
            function cadEstoque(produtodescricaoqtdentradacustouniprecovenda) {
 
                var qtdLinha = tabela.rows.length;
                var linha = tabela.insertRow(qtdLinha),
                    cells = [];
 
                // para cada field da variável fields
                for (let field of fields) {
                    // adiciona uma célula à linha
                    cells[field] = linha.insertCell();
 
                    // cria um elemento de texto
                    let textElement = document.createTextNode(eval(field));
 
                    // adiciona o texto à célula
                    cells[field].appendChild(textElement);
                }
            }
 
        </script>
            
Link to post
Share on other sites

1 answer to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      148952
    • Total Posts
      645026
×
×
  • Create New...