<script type='text/javascript'>window.mod_pagespeed_start = Number(new Date());</script>
cara tentei como você me orientou e ainda não deu certo (ôh burrice abagualada tchê)
vou fazer assim
vou te passar a sequencia de scripts pra que você veja o funcionamento
esse abaixo é o exibe.php
<?PHP
require("db.php");
if ($_GET['p']==NULL)
{
header("Location:index.php");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html" charset="UTF-8"/>
<title>Ofertas</title>
<script>
function zebra(id, classe) {
var tabela = document.getElementById(id);
var linhas = tabela.getElementsByTagName("tr");
for (var i = 0; i < linhas.length; i++) {
((i%2) == 0) ? linhas[i].className = classe : void(0);
}
}
</script>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function DoPrinting(){
if (!window.print){
alert("Use o Netscape ou Internet Explorer \n nas versões 4.0 ou superior!")
return
}
window.print()
}
</script>
</head>
<style>
* { font-family:Arial, Helvetica, sans-serif; font-size:24px; }
h1 { font-size:36px; color:#e63c1e; }
th, td { padding:2px; border-bottom:1px solid #ddd; text-align:left; font-family:Arial, Helvetica, sans-serif; font-size:18px;}
th { background:#e63c1e; font-weight:bold; color:#fff; }
tr.zb td { background:#eee; }
.link{font-size:12px; width:25%; padding:4px;}
.preço{width:14%; margin-top:auto; padding:4px; background-image:url(images/preço.png); width:100px; height:20px; color:#FFF;}
.produto{color:#666; font-style:italic; padding:4px;}
</style>
<body>
<div id="wrapper">
<?php
require("db.php");
if (isset($_GET['p']))
{
$id=(int)$_GET['p'];
}
//$looph=3;
$res = mysql_query("SELECT * FROM anunciantes WHERE `id_anun` = $id");
$i=1;
while ($linha = mysql_fetch_array($res)){
echo '<td><img src="'.$linha['caminho_foto']. $linha['foto'].'" width="980" height="300"></td>
';
?>
<table width="500px" cellpadding="0" cellspacing="0" id="wrapper">
<tr><td colspan="3">
<?php
echo $linha['nome_anun'];
}
?>
</td></tr>
<tr>
<?php
if (isset($_GET['p']))
{
$id=(int)$_GET['p'];
}
require("db.php");
//$looph=2;
$res = mysql_query("SELECT * FROM integrantes WHERE `id_anun` = $id ");
$i=1;
while ($list = mysql_fetch_array($res)){
//if($i < $looph){
echo '<td class="produto">'.$list['produto'].'</td>';
//}elseif($i = $looph){
echo '<td class="preço"><b>R$ '.number_format($list['valor'],2,',','.').'
</b></td>';
echo '<td class="link"><a href="processa.php?add='.$list['id'].'"> <img src="images/icon1.png" width="25" height="20" alt="Adicionar a lista de compras" title="Adicionar a lista de compras" /><br />Adicionar à lista de Compras</a>
</td>
</tr>
<tr>
';
$i = 0;
}
$i++;
//}
?>
</tr>
<tr><td colspan="3">
<?php
$data = mysql_query("SELECT * FROM limite_oferta WHERE `id_anun` = $id ");
$list = mysql_fetch_array($data);
?>
<?php echo "<p style='color:#000000; font-size:12px; text-align:center;'> Ofertas válidas até <b><u>$list[data]</u></b> ou enquanto durarem os estoques.</p>"; ?>
<?php echo "<a href='javascript:history.go(-1)'>Voltar</a>"; ?>
</td></tr>
</table>
<div id="footer">
</div>
<script>zebra('minhatabela','zb');</script>
</div>
</body>
</html>
você vai observar que eu passo os dados via GET para o arquivo processa.php passando o ID do produto.
o processa php é esse abaixo:
<?php
session_start();
//session_destroy();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sem título</title>
<style rel="stylesheet" type="text/css" media="print">
#botao {
display: none
}
</style>
<style>
.total{font:Arial, Helvetica, sans-serif;
font-size:18px;
font-weight:bold;}
.total2{font:Arial, Helvetica, sans-serif;
font-weight:bold;
font-style:italic;
}
.lista{
padding:4px;
}
</style>
</head>
<body>
<?php
//instanciar a página do carrinho
$pagina = 'carrinho.php';
//inicio da class
function conexao(){
//conexão com banco de dados
mysql_connect($this->hostname, $this->login, $this->senha) or die("Não foi possível validar os dados".mysql_error());
mysql_select_db($this->banco) or die("Não foi possível conectar ao banco".mysql_error());
mysql_query("SET NAME 'utf-8'");
mysql_query("SET character_set_connection='utf-8'");
mysql_query("SET character_set_clien='utf-8'");
mysql_query("SET character_set_results='utf-8'");
}
//mostrar carrinho de compra
function carrinho (){
$soma=0;
//verificar session
if($_SESSION){
foreach($_SESSION as $nome=>$quantidade){
if ($quantidade>0){
if(substr($nome,0,9) == 'produtos_'){
// pegar id da session
$id = substr($nome,9,(strlen($nome) -9));
$PD = mysql_query("SELECT id,id_anun, produto, valor FROM integrantes WHERE id=".mysql_real_escape_string((int)$id));
while($list = mysql_fetch_array($PD)){
$AN = mysql_query("SELECT `anunciantes`.`id_anun`, `anunciantes`.`nome_anun` FROM `anunciantes` WHERE id_anun=".mysql_real_escape_string($list['id_anun'])." GROUP BY `anunciantes`.`id_anun`");
$anun = mysql_fetch_assoc($AN);
$subtotal = $quantidade * $list['valor'];
echo '
<tr>
<td class="lista total2">'.$anun['nome_anun'].'</td>
<td class="lista total2">'.$list['produto'].'</td>
<td class="lista total2">'.$quantidade.' X</td>
<td class="lista total2">R$ '.number_format($list['valor'],2,',','.').'</td>
<td class="lista total2"><a href="processa.php?add='.((int)$id).'"><img src="images/add.png" ="Aumentar Quantidade" width="20" height="20"></a></td>
<td class="lista"><a href="processa.php?menos='.((int)$id).'"><img src="images/menos.png" ="Diminuir Quantidade" width="20" height="20"></a></td>
<td class="lista"><a href="processa.php?del='.((int)$id).'"><img src="images/remove.png" ="Excluir item" width="20" height="20"></a></td>
<td class="lista" class="total">R$ '.number_format($subtotal,2,',','.').'</td>
<tr>
</tr>
</tr>';
}
}
$soma += $subtotal;
}
}
if($soma == 0){
echo '<td colspan="8" class="total">Sua lista de compras está vazia! </td>';
}else{
echo '<tr>
<tr>
<td colspan="6"class="total">TOTAL </td>
<td colspan="2" class="total" align="right"> R$: '.number_format($soma,2,',','.').'</td>
</tr>
<tr>
<td colspan="8"class="total">
</td>
</tr>
';
}
}
}
//fim class
}
$conecta = new shopping();
$conecta->conexao();
function antiSQL($sql)
{
$seg = preg_replace("/(from|select|insert|delete|where|drop table|show tables|#|\*|--|\\\\)/","",$sql); //remove palavras que contenham a sintaxe sql
$seg = trim($seg); //limpa espaços vazios
$seg = strip_tags($seg); // tira tags html e php
$seg = addslashes($seg); //adiciona barras invertidas a uma string
return $seg;
}
if(isset($_GET['add'])){
$id_produto=$_GET['add'];
$id_produto=antiSQL($id_produto);
$id_produto=(int)$id_produto;
$VER=(mysql_query("SELECT `integrantes`.`id` FROM `integrantes` WHERE id=".$id_produto));
$conta=mysql_num_rows($VER);
if($conta==1)
{
$_SESSION['produtos_'.$_GET['add']] += '1';//(isset($_SESSION['produtos_'.$_GET['add']])) ? $_SESSION['produtos_'.$_GET['add']] + 1 : 1;
header("Location:".$pagina);
}else{
echo "Produto não cadastrado";
}
}
//exclusão de item
if(isset($_GET['del'])){
$_SESSION['produtos_'.$_GET['del']]= '0';//(isset($_SESSION['produtos_'.$_GET['del']])) ? $_SESSION['produtos_'.$_GET['del']] == 0 : 0;
header('Location:'.$pagina);
}
//subtração de item
if(isset($_GET['menos'])){
$_SESSION['produtos_'.$_GET['menos']]--;//(isset($_SESSION['produtos_'.$_GET['del']])) ? $_SESSION['produtos_'.$_GET['del']] == 0 : 0;
header('Location:'.$pagina);
}
?>
</body>
</html>
funciona da seguinte forma:
na tela do arquivo exibe.php eu mostro as ofertas de um determinado anunciante
cada produto anunciado tem um link que manda seu respectivo id para o arquivo processa.php via query string
o arquivo processa, monta a lista mostrando anunciante, produto, valor unitário, quantidade, subtotal e total, porém pode-se acrescentar ofertas de ' N ' anunciantes, conforme a necessidade do usuário.
eu quero colocar. ao final da lista, a possibilidade do usuário escolher se quer ou não exibir e imprimir junto com sua lista de ofertas selecionadas, o endereço dos anunciantes cujas ofertas ele selecionou.
desde já agradeço a boa vontade do amigo, mas programação é assim mesmo, os que sabem menos aprendem com os que sabem mais e depois passam o conhecimento adiante