Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Galéra, seguinte.
Eu tenho um while que mostra umas informações do banco de dados.
só que eu preciso mostrar:
PRODUTOS LISTADOS
OUTRAS INFORMAÇÕES QUE NÃO ENVOLVEM BANCO DE DADOS...
LISTAR OS ESTABELECIMENTOS ONDE OS ITENS ACIMA SE ENCONTRAM
Se eu continuar com o While, as informações que não envolvem BD, também vão se repetir...
Mas elas não podem se repetir...
Então tentei um for... Mas não consegui, pois fica listando apenas o ultimo resultado.
abaixo está o codigo da pagina completo.
<?
include "charset.php";
include "condb.php";
include "session.php";
?>
<?
$idusuario = $_SESSION["idusuario_cadastrados"];
$sql = "select * from carrinhos where idusuario_cadastrados=$idusuario";
$rs = mysql_query($sql);
$row = mysql_num_rows($rs);
$row2 = mysql_fetch_array($rs);
if ($row == "") { echo "<img src='tmp_img/carrinhovazio.jpg' width='500' height='169' />";} else {
?>
<link href="css/leaf.css" rel="stylesheet" type="text/css" />
<form name="form" method="post" action="#">
<table width="780" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td valign="top" class="sobre_corpo_texto">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<table width="95%" border="0" cellspacing="3" cellpadding="0">
<tr>
<td><span class="titulo_cadastro_form">Seu carrinho</span><span class="busca_preco"><img src="tmp_img/seta_form.jpg" alt="" width="15" height="18" /></span></td>
</tr>
<tr>
<td width="66%"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="37%" class="topo_cadastrese">Nome/ Fabricante / Peso</td>
<td width="27%" class="topo_cadastrese">Estabelecimento</td>
<td width="13%" class="topo_cadastrese">Quantidade</td>
<td width="23%" class="topo_cadastrese">Valor</td>
</tr>
</table></td>
</tr>
<tr>
<td>
<table width="100%" border="0" cellspacing="3" cellpadding="0">
<? while ($row=mysql_fetch_array($rs)) { ?>
<? ### select produto;
$idproduto = $row["idproduto"];
$sqlproduto = "select * from produtos where idproduto=$idproduto";
$rsproduto = mysql_query($sqlproduto);
$rowproduto = mysql_fetch_array ($rsproduto);
### select mercado
$idmercado = $row["idusuario_estabelecimentos"];
$sqlmercado = "select * from usuarios_estabelecimentos where idusuario=$idmercado";
$rsmercado = mysql_query($sqlmercado);
$rowmercado = mysql_fetch_array ($rsmercado);
?>
<input name="idcarrinho[]" type="hidden" value="<?=$row["idcarrinho"]?>" />
<input name="idestabelecimento[]" type="hidden" value="<?=$row["idusuario_estabelecimento"]?>" />
<input name="idcadastrados[]" type="hidden" value="<?=$row["idusuario_cadastrados"]?>" />
<input name="idproduto[]" type="hidden" value="<?=$row["idprotudo"]?>" />
<input name="quantidade2[]" type="hidden" value="<?=$row["qtd_item"]?>" />
<tr>
<td width="37%" valign="middle" class="busca_produto"><strong><?=$rowproduto["nome"]?></strong>
/
<?=$rowproduto["fabricante"]?>
<?=$rowproduto["peso"]?><em><?=$rowproduto["tipo_valor"]?></em></td>
<td width="27%" valign="middle" class="busca_produto"><?=$rowmercado["nome_fantasia"]?></td>
<td width="13%" valign="middle" class="busca_produto">
<input name="quantidade[]" type="text" class="formulario_cadastro" id="textfield11" value="<?=$row['qtd_item']?>" size="2" maxlength="5" /></td>
<td width="15%" valign="middle" class="busca_produto">
R$ <? @$valorformatado = number_format($rowproduto['valor'],2,",","."); echo @$valorformatado;?> </td>
<td width="8%" valign="middle" class="busca_produto"><a title="RETIRAR PRODUTO DO CARRINHO" href="retirardocarrinho.php?id=<?=$row["idcarrinho"]?>"><img src="icones/001_04.gif" width="24" height="24" border="0" /></a></td>
</tr>
<?
$valormultiplicado = $rowproduto["valor"] * $row["qtd_item"];
@$valorproduto = $valormultiplicado + $valorproduto;
} ?>
</table></td>
</tr>
<tr>
<td><label></label></td>
</tr>
<tr>
<td><div align="left">
<table width="92%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="1%"><div align="right" class="produto_nome"></div></td>
<td width="68%"><input name="alterar" type="submit" class="formulario_cadastro" id="button" value="Atualizar quantidade de produtos!" />
<input name="esvaziarcarrinho" type="submit" class="formulario_cadastro" id="button2" value="Esvaziar carrinho." /></td>
<td width="31%"><div align="right" class="produto_nome">TOTAL R$
<? @$valorfinal = number_format($valorproduto,2,",","."); echo @$valorfinal;?>
</div></td>
</tr>
</table>
</div></td>
</tr>
<tr>
<td height="39"> </td>
</tr>
<tr>
<td><span class="titulo_cadastro_form">Informações </span><span class="busca_preco"><img src="tmp_img/seta_form.jpg" alt="" width="15" height="18" /></span></td>
</tr>
<tr>
<td class="busca_produto">
<?
##################################################################AQUI QUE ESTÁ A m***** xD
for($x = 0; $x < count($idmercado); $x++)$sqlm= "select * from usuarios_estabelecimentos where idusuario=$idmercado[$x]";
$rsm = mysql_query($sqlm);
$rows = mysql_fetch_array($rsm)?>
<?=@$rows["nome_fantasia"]?>:<?=@$rows["rua_numero"]?>,<?=@$rows["bairro_cidade"]?>/<?=@$rows["uf"]?><br />
<?=@$rows["tel_2"]?><br />
<img src="icones/mastercard.png" width="32" height="32" /><img src="icones/visa.png" width="32" height="32" /><img src="icones/sodex.jpg" alt="" width="31" height="24" />
<?
} ##################################################################E ACABA AQUI!!!!!!!!!!!!!!!!!!!
?>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><a href="imprimir.php" target="_blank">[Imprimir]</a> [Salvar como lista padrão] [Salvar lista *.DOC]</td>
</tr>
</table>
</td>
<td> </td>
</tr>
</table>
<p> </p>
</td>
</tr>
</table></td>
</tr>
</table>
</form>
<?
if (@$_POST["alterar"]){
for($i = 0; $i < count($idcarrinho); $i++)
{
$qtd = $_POST["quantidade"];
$idcarrinho= $_POST["idcarrinho"];
$sqlupdate= "update carrinhos set qtd_item=$qtd[$i] where idcarrinho=$idcarrinho[$i]";
$rsupdate = mysql_query($sqlupdate);
?>
<script><?
}
}
if (@$_POST["esvaziarcarrinho"]){
?>
<script><? }
}?>
Galéra, desde já agradeço, até a boa vontade em dar uma olhada pra ver do que se trata! http://forum.imasters.com.br/public/style_emoticons/default/joia.gif
Carregando comentários...