..:: MX Studio Fóruns ::..: Salvar Resultado de While em 1 Campo MySQL - ..:: MX Studio Fóruns ::..

Jump to content

Publicidade




ATENÇÃO

Para evitar posts desnecessários e que não influam para o andamento e desenvolvimento do fórum, clique aqui e leia todas as regras.
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Salvar Resultado de While em 1 Campo MySQL

#1 User is offline   Helcio Macedo 

  • Group: Membros
  • Posts: 5
  • Joined: 12-August 09

Posted 03 March 2011 - 01:07 PM

Ae galera.. preciso novamente da ajuda de vcs!!


Seguinte.. to fazendo um gerador de folha de pedido de produtos (tipo nota fiscal)
Todo o script do gerador funciona perfeitamente.. soh que..

preciso agora gravar as linhas onde ficam os produtos no meio do 'talão'

tentei a seguinte forma
$prodlist = "
<tr>
<td class=style4>$codigo</td>
<td class=style4>$qnt</td>
<td class=style4>$descricao</td>
<td class=style4>$caixa</td>
<td class=style4>R$$valor</td>
<td class=style4>R$$ptotal</td>
</tr>
";

mysql_query("INSERT INTO `pedidos` (`bllablablabla`,`produtos`,`blbablablablabla`) VALUES ('$blablablabla','$prodlist','$blablablabla')") or die(mysql_error());



Porém se tiver mais de 1 linha de resultado no WHILE ele só grava a ultima!!
Como faço pra gravar todas as linhas??

Segue o código:
PS* se por a query dentro do while ele cria 1 linha para cada resultado do while!

<?

mysql_connect($host,$login,$senha) or die("Erro ao conectar no banco de dados [1] CF0x005");
mysql_select_db($db) or die("Erro ao selecionar o banco de dados [2] CF0x006");

$psql = "SELECT * FROM `produtos` ORDER BY id ASC";
$pres = mysql_query($psql);

// Nota 1
$ncodigo = isset($_POST["codigo"]) ? addslashes(trim($_POST["codigo"])) : FALSE;
$pjuridica = isset($_POST["pjuridica"]) ? addslashes(trim($_POST["pjuridica"])) : FALSE;
$cnpj = isset($_POST["cnpj"]) ? addslashes(trim($_POST["cnpj"])) : FALSE;
$ie = isset($_POST["ie"]) ? addslashes(trim($_POST["ie"])) : FALSE;
$endereco = isset($_POST["endereco"]) ? addslashes(trim($_POST["endereco"])) : FALSE;
$bairro = isset($_POST["bairro"]) ? addslashes(trim($_POST["bairro"])) : FALSE;
$cidade = isset($_POST["cidade"]) ? addslashes(trim($_POST["cidade"])) : FALSE;
$uf = isset($_POST["uf"]) ? addslashes(trim($_POST["uf"])) : FALSE;
$cep = isset($_POST["cep"]) ? addslashes(trim($_POST["cep"])) : FALSE;
$telefone = isset($_POST["telefone"]) ? addslashes(trim($_POST["telefone"])) : FALSE;
$vendedor = isset($_POST["vendedor"]) ? addslashes(trim($_POST["vendedor"])) : FALSE;
$comprador = isset($_POST["comprador"]) ? addslashes(trim($_POST["comprador"])) : FALSE;
$pagto = isset($_POST["pagto"]) ? addslashes(trim($_POST["pagto"])) : FALSE;
$tipo = isset($_POST["tipo"]) ? addslashes(trim($_POST["tipo"])) : FALSE;

// Nota 2
$frete = isset($_POST["frete"]) ? addslashes(trim($_POST["frete"])) : FALSE;
$obsi = isset($_POST["obs"]) ? addslashes(trim($_POST["obs"])) : FALSE;
$desconto = isset($_POST["desc"]) ? addslashes(trim($_POST["desc"])) : FALSE;
$tid = isset($_POST["transp"]) ? addslashes(trim($_POST["transp"])) : FALSE;

 $desconto = number_format($desconto, 2, ',', '.');

$obs = nl2br("$obsi");
$data = date("d/m/Y");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>xxxxxxxx</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="css/main.css"></head>
<style type="text/css">
.style1 {
        border: 1px solid #000000;
        background-color: #FFFFFF;
        font-size: 9px;
}
.style2 {
        border-style: none;
        border-width: 0;
        font-size: 9px;
}
.style3 {
        border-color: #000000;
        border-width: 0;
        font-size: 9px;
}
.style4 {
        border-color: #000000;
        border: 1px solid #000000;
        font-size: 9px;
}
.style5 {
        border: 1px solid #000000;
        background-color: #FFFFFF;
        font-size: 9px;
        text-align: center;
}
</style>

</head>
<body>
<?
$psqt = "SELECT * FROM `transportadora` WHERE id='$tid' ORDER BY id ASC";
$prest = mysql_query($psqt);

while ($recc = mysql_fetch_array($prest)){
                
$tid = "$recc[id]";
$trazaosocial = "$recc[razaosocial]";
$tendereco = "$recc[endereco]";
$tbairro = "$recc[bairro]";
$tcidade = "$recc[cidade]";
$tcnpj = "$recc[cnpj]";
$tie = "$recc[ie]";
$testado = "$recc[estado]";
$tfone = "$recc[fone]";
$tcontato = "$recc[contato]";
$vfrete = "$recc[preco]";

 $vfrete = number_format($vfrete, 2, ',', '.');
}
echo "
<div id='print' align='center'>
<table style='width: 100%' class='style1' cellpadding='0' cellspacing='0'>
        <tr>
                <td align='center'><img src='images/cf_logo.jpg'></td>
                <td align='center'><b>xxxxxxx</b><br />
                <small>xxxxxxxxxxx<br />
                xxxxxxxxxxxxx<br />
                xxxxxxxxxxxx</small></td>
                <td align='center'><img src='images/docitos_logo.jpg'></td>
        </tr>
        <tr>
                <td colspan='3'>
                        <table style='width: 100%' class='style3'>
                                <tr>
                                        <td style='width: 200px' class='style1'>
                                                <strong>Código</strong>: $ncodigo</td>
                                        <td colspan='2' class='style1'>
                                                <strong>Razão Social: </strong>$pjuridica</td>
                                        <td class='style1'>
                                                <strong>Data: </strong>$data</td>
                                </tr>
                                <tr>
                                        <td colspan='2' class='style1'>
                                                <strong>End:</strong> $endereco</td>
                                        <td class='style1'><strong>
                                                Bairro:</strong> $bairro</td>
                                        <td class='style1'>
                                                <strong>Fone:</strong> $telefone</td>
                                </tr>
                                <tr>
                                        <td colspan='3' class='style1'>
                                                <strong>Cidade/UF:</strong> $cidade/$uf</td>
                                        <td class='style1'>
                                                <strong>CEP:</strong> $cep</td>
                                </tr>
                                <tr>
                                        <td class='style1'>
                                                <strong>CNPJ:</strong> $cnpj</td>
                                        <td class='style1'>
                                                <strong>Insc. Est:</strong> $ie</td>
                                        <td class='style1'><strong>
                                                Cond. Pagto:</strong> $pagto</td>
                                        <td class='style1'>&nbsp;
                                                </td>
                                </tr>
                        </table>
                </td>
        </tr>
        <tr>
                <td colspan='3'><br />
                        <table style='width: 100%''>
                                <tr>
                                        <td class='style4'><strong>
                                                Código</strong></td>
                                        <td class='style4'><strong>
                                                Quant.</strong></td>
                                        <td class='style4'><strong>
                                                Descrição</strong></td>
                                        <td class='style4'><strong>
                                                Caixa</strong></td>
                                        <td class='style4'><strong>
                                                Valor Unit.</strong></td>
                                        <td class='style4'><strong>
                                                Valor Total</strong></td>
                                </tr>";

while ($rec = mysql_fetch_array($pres)){
                
$id = "$rec[id]";
$codigo = "$rec[codigo]";
$descricao = "$rec[descricao]";
$caixa = "$rec[caixa]";

$qnt = isset($_POST["p$id"]) ? addslashes(trim($_POST["p$id"])) : FALSE;
$valor = isset($_POST["p$caixa"]) ? addslashes(trim($_POST["p$caixa"])) : FALSE;
 $valor = number_format($valor, 2, ',', '.');

$ptotal = ($qnt * $valor);
 $ptotal = number_format($ptotal, 2, ',', '.');
$subtotal += "$ptotal";
 $subtotal = number_format($subtotal, 2, ',', '.');


$prodlist = "
<tr>
        <td class=style4>$codigo</td>
        <td class=style4>$qnt</td>
        <td class=style4>$descricao</td>
        <td class=style4>$caixa</td>
        <td class=style4>R$$valor</td>
        <td class=style4>R$$ptotal</td>
</tr>
";
        if (!$qnt) echo ""; else echo "$prodlist";

$total = ($subtotal+$vfrete)-($desconto); $total = number_format($total, 2, ',', '.');

}

echo "
                        </table>
                </td>
        </tr>
        <tr>
                <td colspan='3'>
                        <table style='width: 100%'>
                                <tr>
                                        <td>
                                                <table style='width: 100%''>
                                                        <tr>
                                                                <td class='style4'>
                                                                        <strong>Observações</strong></td>
                                                        </tr>
                                                        <tr>
                                                                <td class='style4'>$obs</td>
                                                        </tr>
                                                </table>
                                        </td>
                                </tr>
                        </table>
                </td>
        </tr>
        <tr>
                <td colspan='3'><br />
                        <table style='width: 100%'>
                                <tr>
                                        <td class='style1'><strong>
                                                Vendedor:</strong> $vendedor</td>
                                        <td class='style1'><strong>
                                                Comprador:</strong> $comprador</td>
                                        <td class='style1'><strong>
                                                        Tipo: </strong>$tipo</td>
                                </tr>
                                <tr>
                                        <td colspan='2'>&nbsp;</td>
                                        <td class='style1'><strong>
                                                Sub-Total:</strong> $subtotal</td>
                                </tr>
                                <tr></tr>
                                <tr></tr>
                                <tr>
                                        <td class='style1'><strong>
                                                Frete: </strong>$frete</td>
                                        <td class='style1'><strong>
                                                Desconto:</strong> R$$desconto</td>
                                        <td class='style1'><strong>
                                                Frete: </strong>R$$vfrete</td>
                                </tr>
                                <tr>
                                        <td colspan='2'>&nbsp;</td>
                                        <td class='style1'><strong>
                                                <big><big>TOTAL: </strong>R$$total</big></big></td>
                                </tr>
                        </table>
                </td>
        </tr>
        <tr>
                <td colspan='3'>
                        <table style='width: 100%' class='style2'>
                <tr>
                                        <td colspan='3' align='center'>&nbsp;</td>
                                </tr>
                                <tr>
                                        <td class='style5' colspan='4'>
                                                <strong>ATENÇÃO: Confira rigorosamente as mercadorias, não serão aceitas reclamações posteriores</strong></td>
                                </tr>
                                <tr>
                                        <td class='style1'>
                                                <strong>Razão Social: </strong>$trazaosocial</td>
                                        <td class='style1'>
                                                <strong>End:</strong> $tendereco</td>
                                        <td class='style1'>
                                                <strong>Bairro:</strong> $tbairro</td>
                                        <td class='style1'>
                                                <strong>Cidade:</strong> $tcidade/$testado</td>
                                </tr>
                                <tr>
                                        <td class='style1'>
                                                <strong>CNPJ: </strong>$tcnpj</td>
                                        <td class='style1'>
                                                <strong>Insc. Est: </strong>$tie</td>
                                        <td class='style1'>
                                                <strong>Fone: </strong>$tfone</td>
                                        <td class='style1'>&nbsp;
                                                <strong>Contato: </strong>$tcontato</td>
                                </tr>                                                                                           
                        </table>
                </td>
        </tr>
</table>
</div>";

mysql_query("INSERT INTO `pedidos` (`codigo`,`razaosocial`,`end`,`bairro`,`cep`,`fone`,`cidade`,`cnpj`,`ie`,`pagto`,`produtos`,`obs`,`vendedor`,`comprador`,`tipo`,`subtotal`,`frete`,`desconto`,`vfrete`,`total`,`trazaosocial`,`tend`,`tbairro`,`tcidade`,`tcnpj`,`tie`,`tfone`,`tcontato`,`data`) VALUES ('$ncodigo','$pjuridica','$endereco','$bairro','$cep','$telefone','$cidade/$uf','$cnpj','$ie','$pagto','$prodlist','$obs','$vendedor','$comprador','$tipo','$subtotal','$frete','$desconto','$vfrete','$total','$trazaosocial','$tendereco','$tbairro','$tcidade/$testado','$tcnpj','$tie','$tfone','$tcontato','$data')") or die(mysql_error());
?>
</body>
</html>

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic


Similar Topics Collapse

  Topic Forum Started By Stats Last Post Info
New Replies Cadastro de produtos Flash PHP MySQL
Por que o resto da descrição não aparece???
Flash & ActionScript ekulykus 
  • 0 Replies
  • 2139 Views
New Replies Campos em branco não são enviados
enviar somente preenchidos ou assinalado
Web Standards ayrtonprospero 
  • 1 Reply
  • 608 Views
New Replies Programadores PHP & ASP (MySQL) + Hospedagens
Precisam-se
Freelancers sitespt 
  • 0 Replies
  • 921 Views
New Replies Bing traz Twitter em seus resultados de busca Notícias Notícias 
  • 0 Replies
  • 162 Views
New Replies Erro ao inserir dados em campo específico!
Duvida com relação a inserção de dados
ColdFusion Leonardo de A. Pereira 
  • 3 Replies
  • 1219 Views
New Replies Problemas utilizando a tag <img>
dentro de campos de texto
Flash & ActionScript moschetta 
  • 0 Replies
  • 459 Views
New Replies Salvando dados em um XML através de um Flash executavel
Salve salve a todos. Gostaria de saber qual a possibilidade de salvar
Flash & ActionScript Julio Farias 
  • 1 Reply
  • 1403 Views
New Replies Consulta em duas tabelas
Consulta em duas tabelas do Mysql
Dreamweaver Felix 
  • 6 Replies
  • 2823 Views

Publicidade




1 User(s) are reading this topic
0 membro(s), 1 visitante(s) e 0 membros anônimo(s)