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'>
</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'> </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'> </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'> </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'>
<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>

Help














