Jump to content


Photo

Tabelas Temporarias No Postgres


  • Faça o login para participar
1 reply to this topic

#1 victormangia

victormangia

    Doutor

  • Usuários
  • 783 posts
  • Sexo:Masculino
  • Localidade:barra mansa - rj

Posted 14/01/2005, 07:52

Galera, fiz um script que faz o seguinte

1- cria uma tabela temporaria no postgres

2- se a tabela existe insere dados nela.

mais o problema 'e o seguinte:

quando eu mando adicionar outros dados ao invez de adicionar esses novos dados ele parece que cria a tabela novamente e adiciona os dados novamente mostrando assim sempre apenas um registro, o mesmo nao acontece se a tabela criada nao for temporaria.

tem como eu pegar os valores ja existentes na tabela, gravar em sessions e depois gravar de volta pra tabela?


O code 'e esse abaixo,

PHP


<?
include "../../postgres/conecta.php";

// Cria tabela temporaria
$criar_tabela=pg_query("
CREATE temporary TABLE \"
item_compra_tmp&#092;" (\"cod_item\" character(70), \"item\" character(50), \"bitola\" character(70), \"item_uni\" character(2), \"item_qnt\" character(70), \"valor_unit\" numeric, \"item_vt\"  character(50), \"ipi\" character(60)) WITHOUT OIDS
");
if (!$criar_tabela)
{
echo "
<font face=arial size=2 color=red>Erro, Nao foi possivel a criacao da tabela temporaria</font><br>";
}
// grava esses items na tabela temporaria
$inserir_na_tabela=pg_query("
INSERT INTO &#092;"item_compra_tmp\" (\"cod_item\", \"item\", \"bitola\", \"item_uni\", \"item_qnt\", \"valor_unit\", \"item_vt\") VALUES ('$cod_item', '$item', '$bitola', '$item_uni', '$item_qnt', '$valor_unit', '$item_vt')");
if (!$inserir_na_tabela) {
echo
"<font face=arial size=2 color=red>Erro, Nao foi possivel inserir os dados na tabela</font>";
}
$valor_geral = @pg_fetch_array(pg_query("select sum(valor_unit) as valor_geral from item_compra_tmp"));
$query=@pg_query("select * from item_compra_tmp");
// so mostrar o cabeçalho se achar pelo menos um item
$contagem0 = @pg_num_rows($query);
if (
$contagem0 > 0) {
echo
"<table><TR style='border: 1 solid #000000'><td style='background-color: #D6D6D6; border-style: outset; border-width: 1' width='8'><b><font size='1' face='Arial'><img border='0' src='images/tri-right1.gif' width='8' height='8'></font></b></td><td style='background-color: #D6D6D6; border-style: outset; border-width: 1'><font face='Arial' size='1' color='#000000'>Cod</TD><td style='background-color: #D6D6D6; border-style: outset; border-width: 1' width='210' ><font size='1' face='arial' color='black'>Descrição</font></td><td style='background-color: #D6D6D6; border-style: outset; border-width: 1 ' width='130'><font size='1' face='arial' color='black'>Bitola</font></td><td style='background-color: #D6D6D6; border-style: outset; border-width: 1'><font size='1' face='arial' color='black'>Un.</td><td style='background-color: #D6D6D6; border-style: outset; border-width: 1'><font size='1' face='arial' color='black'>Quant.</font></td><td style='background-color: #D6D6D6; border-style: outset; border-width: 1' ><font size='1' face='arial' color='black'>Valor Unit.</font></td><td style='background-color: #D6D6D6; border-style: outset; border-width: 1' ><font size='1' face='arial' color='black'>Valor Total</font></td><td style='background-color: #D6D6D6; border-style: outset; border-width: 1'><font size='1' face='arial' color='black'>Ipi(%)</font></td></tr>
"
;
?>
<script>
parent.order.sub_compra.value = <? echo $valor_geral[0]; ?>;
parent.multiplicacao();
</SCRIPT>
<?
}
else
{
echo
"<br><br><br><br><br><br><center><font face='arial' size='2'> Sem resultados para exibição!</font></center>";
}
// mostrar items da tabela
while($res=@pg_fetch_array($query)) {  
$cor
=($i%2==0) ? "#f6f6f6" : "#D6D6D6";      
echo "<TR style='border: 1 solid #000000'><td style='background-color: ".$cor."; border-style: outset; border-width: 1' width='8'><b><font size='1' face='Arial'><img border='0' src='images/tri-right1.gif' width='8' height='8'></font></b></td><td style='background-color: ".$cor."; border-style: outset; border-width: 1' width='30'><font face='Arial' size='1' color='#000000'>
$res
[cod_item]
</TD><td style='background-color: "
.$cor."; border-style: outset; border-width: 1' ><font size='1' face='arial' color='black'>
$res
[item]
</font></td><td style='background-color: "
.$cor."; border-style: outset; border-width: 1' ><font size='1' face='arial' color='black'>
$res
[bitola]
</font></td><td style='background-color: "
.$cor."; border-style: outset; border-width: 1' ><font size='1' face='arial' color='black'>
$res
[item_uni]
</td><td style='background-color: "
.$cor."; border-style: outset; border-width: 1' ><font size='1' face='arial' color='black'>
$res
[item_qnt]
</font></td><td style='background-color: "
.$cor."; border-style: outset; border-width: 1' width='30'><font size='1' face='arial' color='black'>
$res
[valor_unit]
</font></td><td style='background-color: "
.$cor."; border-style: outset; border-width: 1' width='30'><font size='1' face='arial' color='black'>
$res
[item_vt]
</font></td><td style='background-color: "
.$cor."; border-style: outset; border-width: 1' width='30'><font size='1' face='arial' color='black'>
$res
[ipi]
</font></td></tr>"
;
$i++;
}
echo
"</table>
"
;
?>

Edição feita por: victormangia, 14/01/2005, 12:13.


#2 RonsisM

RonsisM

    Super Veterano

  • Usuários
  • 15724 posts
  • Sexo:Masculino
  • Localidade:Plovdiv

Posted 29/10/2017, 14:37

Cialis Pastillas Toradol From Canada viagra My Canadian Pharmacy Corp




0 user(s) are reading this topic

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

IPB Skin By Virteq