Jump to content


Photo

CRIAR ARRAY E ADICIONAR EM UMA TABLE

php array table

  • Faça o login para participar
Nenhuma resposta neste tópico

#1 Loh2

Loh2

    Novato no fórum

  • Usuários
  • 2 posts
  • Sexo:Feminino
  • Localidade:Uberlândia

Posted 22/05/2016, 16:41

Pessoal, sou iniciante em php e estou precisando de ajuda.
Como faço para pegar o input de um usuário, adicioná-lo em um array e exibi-lo em uma table?

Tenho esse código:

 

 

    <form  method = "post">
        <div class="form-group">
            <label style="margin-left: 35px;">• Produto </label>
            
                
                    <select id="cboProduto" name= "produto" style="margin-left: 45px; width: 210px; height: 30px;padding-left:8px;">
                    <?php 
                        $query = 'SELECT * from tab_produto where flag_produto LIKE "venda" order by nome_produto';
                        $result = mysql_query($query) or die("Falha na execução da consulta");
                        while($row1 = mysql_fetch_assoc($result))
                        {                
                            $produto = $row1['id_produto'];
                            $nomeproduto = $row1['nome_produto'];
                    ?>                        
                            <option value="<?php echo $produto;?>"><?php echo $nomeproduto;?></option>
                            <?php 
                        }     ?>    
                    </select>
                    
                    
                    <?php
                        $sql = "SELECT * FROM tab_produto WHERE id_produto = '$produto'";
                        $rs = mysql_query($sql);        
                        while($reg = mysql_fetch_array($rs))
                        {    
                            $produtos[] = array('nome_produto' => $reg['nome_produto'], 'valor_produto' => $reg['valor_produto']);
                        }
                    ?>

            <label style="margin-left: 35px;">• Quantidade</label>
            <td><input style="margin-left: 15px; width: 100px; height: 30px;padding-left:10px;" name="quantidade" type="text" id="txtQuant" >
            <button class="btn btn-primary" style="margin-left: 15px" type="submit" id="btnAdicionar"> + </button>
            <a href="EfetuarVenda.php" class="btn btn-danger" role="button">Nova Venda</a>
            
        </div>                
    </form>
            
    
    <hr>
        <div class="container"style="margin-left:30px; width:1000px;">
            <div class="row">
                <div class="col-xs-12">
                    <div class="table-responsive">
                        <table class="table table-bordered">
                            <thead>
                                <tr class="active">
                                    <th style="width:115px; padding-left:40px;">Data</th>
                                    <th style="width:180px; padding-left:60px;">Produto</th>
                                    <th style="width:115px; padding-left:18px;">Quantidade</th>
                                    <th style="width:125px; padding-left:15px;">Preço Unitário</th>
                                    <th style="width:135px; padding-left:10px;">Total do Produto</th>
                                    <th style="width:135px; padding-left:10px;">Total Compra</th>
                                    <?php 
                                    $data = date("Y-m-d");
                                    $soma = 0;
                                    $dati = explode("-", $dato[$j]);
                                    $dataconvertida[$j]=$dati[2]."/".$dati[1]."/".$dati[0];
                                    $j=1;
                                    
                                    ?>
                                </tr>
                            </thead>
                            
                            <tbody>
                                <tr class="success">

                                    <td style="padding-left:15px;"><?php echo $dataconvertida[$i];?></td>
                                    <td style="padding-left:30px;"><?php echo $produtos[$cont][nome_produto]?></td></td>
                                    <td style="padding-left:30px;"><?php echo $quantidade[$i];?></td></td>
                                    <td style="padding-left:35px;"> R$<?php echo $produtos[$cont][valor_produto];?></td></td>
                                    <td style="padding-left:35px;"> R$<?php echo $produtos[$cont][valor_produto]*$quantidade[$i];?></td></td>
                                    <td style="padding-left:30px;"> R$ <?php $preço = (float)$preço; $total = (float)$total; $soma=(float)$soma; $total = $quantidade[$i]*$preço;  $soma = $soma + $total; echo $soma;?></td></td>
                                    <td><a href="excluirVenda.php?produto=<?php echo $codigoprodutoinserido[$i];?><?php echo $produto[$i];?>&cpf=<?php echo $cpfselecionado;?>&data=<?php echo $dato[$i];?>&quantidade=<?php echo $quantidade[$i];?>" class="btn btn-danger" role="button">Excluir Produto</a></td></td>
                                </tr>
                            </tbody>
                            
                        </table>
                    </div>
                </div>
            </div>
        </div>







Veja alguns posts relacionados com: php, array, table

0 user(s) are reading this topic

0 membro(s), 0 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq