Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Kelven

[Resolvido] Listagem de produtos na horizontal.

Recommended Posts

E ai galera beleza,

Ou pessoal to com problema em listagem de produtos na horizonta,

eu queria fazer tipo assim,

como toda loja virtual a listagem de produtos sempre é na horizontal e vai caindo o resto dos produtos pra baixo dos primeiros, mas eu fiz aqui e o produto só ta listando pra baixo não lista pro lado também olhem só o código,

<?php include("conexao.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>Loja virtual</title>
</head>

<body style="margin:auto; text-align:center; font:Verdana, Geneva, sans-serif; font-size:12px;">


<table width="800px" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td colspan="3" style="text-align:center; background-color:#000" width="100%">
    <a href="index.php"><?php  include("topo.php");?></a></td>
  </tr>
  <tr>
  
  <!-- Toda a parte do menu em php -->
    <td width="113" style="text-align:center"><?php $sql = "SELECT * FROM categoria";
$resultado = mysql_query($sql) or die ("ouve um erro ao mostrar os arquivos, talvez seja erro de banco de dados entre em contato contato@flycratry.com");
while($registro=mysql_fetch_array($resultado))
{
	?>
<a href="index.php?id=<?php echo $registro[id] ?>"><?php echo $registro[categoria];?></a><br />
<?php 
$id_para_subcategoria= $_GET["id"];
if($id_para_subcategoria != "")
{
	
	$sql2 = "SELECT * FROM subcategorias WHERE id_categoria = '$registro[id]'";
	$resultado_subcategorias = mysql_query($sql2) or die ("tem erro no script");
	while($registro2= mysql_fetch_array($resultado_subcategorias))
	{
		
	if ($id_para_subcategoria == $registro2[id_categoria])
	{
	?>
   --<a href="index.php?id_categoria=<?php echo $registro2[id_categoria]; ?>&id_subcategoria=<?php echo $registro2[id_subcategoria]; ?>">kelven muitodoido</a><br />
<?php
	}
	}
	
	}
?>


<?php
}?>
<!-- fim da parte do menu em php -->

</td>
    <td width="177" style="text-align:center">
    <?php 
	$id_categoria = $_GET["id"];
	if ($id_categoria == "")
	{
	?>
    conteudo
    <?php }
	else
	{
		
		/* Parte do produto*/
		$sql3 = "SELECT * FROM produtos WHERE id_categoria = '$id_categoria'";
		$resultado_produtos = mysql_query($sql3) or die ("tem um erro no script");
		while($registro3= mysql_fetch_array($resultado_produtos))
	{
	?>
    
    <table width="208" bordercolor="#CCCCCC" border="1" cellspacing="0" cellpadding="0">
  <tr>
    <td colspan="2" style="text-align:center"><img src="adfasfasdfasdf" width="50" height="50" /></td>
    </tr>
  <tr>
    <td colspan="2" style="text-align:center"><?php echo $registro3[nome];?></td>
    </tr>

  <tr>
    <td width="181" style="text-align:center"><a href="detalhes.php?id_produto=<?php echo $registro3[id_produto];?>">detalhes</a></td>
    <td width="108" style="text-align:center"><a href="carrinho.php?id_produto=<?php echo $registro3[id_produto];?>">Adicionar a carrinho</a></td>
  </tr>
</table>

    
    
     <?php 
	}
	 }?>
    
    </td>
    <td width="82" style="text-align:center"> propaganda </td>
  </tr>
  <tr>
    <td colspan="3" style="text-align:center">Rodapé</td>
  </tr>
</table>

</body>
</html>

O que eu posso fazer pra listar o produto pro lado também?

Compartilhar este post


Link para o post
Compartilhar em outros sites

while($registro3= mysql_fetch_array($resultado_produtos))
        {
        ?>
    
    <table width="208" bordercolor="#CCCCCC" border="1" cellspacing="0" cellpadding="0">
  <tr>
    <td colspan="2" style="text-align:center"><img src="adfasfasdfasdf" width="50" height="50" /></td>
    </tr>
  <tr>
    <td colspan="2" style="text-align:center"><?php echo $registro3[nome];?></td>
    </tr>

  <tr>
    <td width="181" style="text-align:center"><a href="detalhes.php?id_produto=<?php echo $registro3[id_produto];?>">detalhes</a></td>
    <td width="108" style="text-align:center"><a href="carrinho.php?id_produto=<?php echo $registro3[id_produto];?>">Adicionar a carrinho</a></td>
  </tr>
</table>

    
    
     <?php 
        }

Dessa forma, a cada loop do while, o programa está criando uma tabela NOVA. Insira nesta tabela somente as colunas que você deseja criar.

Para configurar quantas colunas por linha, utilize como está aqui: http://forum.imasters.com.br/index.php?/topic/409460-4-resultados-por-coluna/

 

Resumindo: você deixa o table para fora do while, verifica se é o primeiro loop, se for adiciona a tag de linha <tr>, adiciona a coluna, e se for a N vez, fecha a tag de linha </tr>.

 

Quaisquer dúvidas, volte aqui.

 

Até mais.

Compartilhar este post


Link para o post
Compartilhar em outros sites

h4x0r você pode fazer um exemplo ai nessa tabela para mim ver como é que fica porque eu tentei fazer e não deu certo.

Compartilhar este post


Link para o post
Compartilhar em outros sites

echo '<table width="208" bordercolor="#CCCCCC" border="1" cellspacing="0" cellpadding="0">';
$i = 0;
while($x = mysql_fetch_array($resultado_produtos)) {
	++$i;
	echo ($i==0) ? '<tr>' : null;
	?>
	<td>
		<img src="adfasfasdfasdf" width="50" height="50" style="float:left;" /></td>
		<?php echo $x['nome'];?><br />
		<a href="detalhes.php?id_produto=<?php echo $x['id_produto'];?>">detalhes</a><br />
		<a href="carrinho.php?id_produto=<?php echo $x['id_produto'];?>">Adicionar a carrinho</a>
	</td>
	<?php
	if ($i==4) {
		$i = 0;
		echo '</tr>';
	}
}
echo '</table>';

;)

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.