JFernandesVR Posted May 19, 2014 at 03:01 PM Report #556269 Posted May 19, 2014 at 03:01 PM (edited) Boas pessoa. Como Fazer uma listagem de produtos de 5 produtos por linha, mas sem usar tabelas. eu estou a tentar inserir em div. o problema é que chegando à 5 linha, apenas me lista 2 divs por linha e não exibe <div id="linha"> eu queri que aparecesse o seguinte. a pesquisa está a funcionar perfeitamente. <div id="linha"> <div id="produto">artigo1</div> <div id="produto">artigo2</div> <div id="produto">artigo3</div> <div id="produto">artigo4</div> <div id="produto">artigo5</div> </div> <div id="linha"> <div id="produto">artigo6</div> <div id="produto">artigo7</div> <div id="produto">artigo8</div> <div id="produto">artigo9</div> <div id="produto">artigo10</div> </div> <div id="subfamConteudoMaster"> <div id="subfamConteudo"> <?php $sql2 = "SELECT * FROM artigos WHERE SubFamiliaPT = (SELECT Nome FROM subfamilias WHERE ID = '$id') $ordenar_marcas $ordena_precos $ordenar"; $rs2 = mysql_query($sql2); $num_artigos = mysql_num_rows($rs2); ?> <div id="numArtigosPesq" style="padding-bottom:15px;"><p>Número de Artigos Encontrados : <?php echo $num_artigos ?></p></div> <?php if($num_artigos > 0) { $i = 0; while ($list = mysql_fetch_array($rs2)) { $imgart = $list['Imagem']; $refart = $list['Referencia']; $descart = $list['DescricaoPT']; $pvpart = $list['PrecoPVP']; $revart = $list['PrecoREV']; $empart = $list['PrecoEMP']; $campart = $list['PrecoCAMP']; $validadeart = $list['Validade']; $marcaart = $list['Marca']; $ivaart = $list['Iva']; $totali = new Classe(); ++$i; echo ($i == 0) ? '<div id="linha">' :null; ?> <div id="produto" style="width:166px; float:left; border:0;" class="artigoPesqAvanc"> <?php echo $i; if($campart > 0) { if($validadeart > '0000-00-00') { if(strtotime($datahj) <= strtotime($validadeart)) { ?> <div class="promo1"> <div class="promo"><img src="images/sticker-promo2.png" width="100" height="53" /></div> </div> <?php } } } ?> <div id="imagem" align="center"> <?php if(!$imgart) { ?> <a href="Artigo.php?<?php echo $SID ?>&id=<?php echo $refart ?>"><img src="images/semimagemgr.jpg" title="<?php echo $refart ?>" alt="<?php echo $refart ?>" width="79" height="60"/></a> <?php } else { ?> <a href="Artigo.php?<?php echo $SID ?>&id=<?php echo $refart ?>"><img src="images/artigos/<?php echo $imgart ?>" width="79" height="60" title="<?php echo $refart ?>" alt="<?php echo $refart ?>" /></a> <?php } ?> </div> <div id="descricao"> <p class="prodDESC"><?php echo ucwords(strtolower($descart)) ?></p> </div> <div id="marca" align="right"> <?php if(!$marcaart) { ?><img src="images/semmarca.jpg" width="70" height="49" title="Sem Marca"><br /><?php } else { $sql99 = "SELECT * FROM marcas WHERE Nome = '".$marcaart."'"; $rs99 = mysql_query($sql99); $num99 = mysql_num_rows($rs99); if($num99 > 0) { $reg99 = mysql_fetch_array($rs99); $imgmarca = $reg99['Imagem']; ?> <a href="marca.php?<?php echo $SID ?>&marca=<?php echo $marcaart ?>"> <img src="images/marcas/<?php echo $imgmarca ?>" width="70" height="49" title="<?php echo $marcaart ?>"> </a> <br /> <?php } else { ?><img src="images/semimagempq.jpg" width="70" height="49" title="<?php echo $marcaart ?>"><br /><?php } } ?> </div> <div id="preco"> <?php if(isset($_SESSION['login_status'])) { $tipo = ($_SESSION['tipo']); if($tipo == 'ClientePVP') { if($campart > 0) { if($validadeart > '0000-00-00') { if(strtotime($datahj) <= strtotime($validadeart)) { ?> <span class="prod-desconto"><?php echo $totali->desconto($campart, $pvpart); ?>%</span><p></p> <span class="precoOld"><?php echo $pvpart ?>€</span><br /> <span class="precoPVP" align="right"><?php echo $campart ?>€</span><br /> <!--<span class="precoIVA">c/ iva <b><u><?php echo $totali->calculaivass($ivaart, $campart); ?>€</u></b></span>--> <?php } else { ?> <br /><br /> <span class="precoPVP" align="right"><?php echo $pvpart ?>€</span><br /> <!--<span class="precoIVA">c/ iva <b><u><?php echo $totali->calculaivass($ivaart, $pvpart); ?>€</u></b></span>--><?php } } else { ?> <br /><br /> <span class="precoPVP" align="right"><?php echo $pvpart ?>€</span><br /> <!--<span class="precoIVA">c/ iva <b><u><?php echo $totali->calculaivass($ivaart, $pvpart); ?>€</u></b></span>--><?php } } else { ?> <br /><br /> <span class="precoPVP" align="right"><?php echo $pvpart ?>€</span><br /> <!--<span class="precoIVA">c/ iva <b><u><?php echo $totali->calculaivass($ivaart, $pvpart); ?>€</u></b></span>--><?php } } elseif($tipo == 'Revenda') { if($campart > 0) { if($validadeart > '0000-00-00') { if(strtotime($datahj) <= strtotime($validadeart)) { ?> <br /> <span class="prod-desconto"><?php echo $totali->desconto($campart, $revart); ?>%</span><p></p> <span class="precoOld"><?php echo $revart ?>€</span><br /> <span class="precoREV-EMP" align="right"><?php echo $campart ?>€</span> <?php } else { ?> <br /><br /> <span class="precoREV-EMP" align="right"><?php echo $revart ?>€</span><?php } } else { ?> <br /><br /> <span class="precoREV-EMP" align="right"><?php echo $revart ?>€</span><?php } } else { ?> <br /><br /> <span class="precoREV-EMP" align="right"><?php echo $revart ?>€</span><?php } } elseif($tipo == 'Empresa') { if($campart > 0) { if($validadeart > '0000-00-00') { if(strtotime($datahj) <= strtotime($validadeart)) { ?> <br /> <span class="prod-desconto"><?php echo $totali->desconto($campart, $empart); ?>%</span><p></p> <span class="precoOld"><?php echo $empart ?>€</span><br /> <span class="precoREV-EMP" align="right"><?php echo $campart ?>€</span><?php } else { ?> <br /><br /> <span class="precoREV-EMP" align="right"><?php echo $empart ?>€</span><?php } } else { ?> <br /><br /> <span class="precoREV-EMP" align="right"><?php echo $empart ?>€</span><?php } } else { ?> <br /><br /> <span class="precoREV-EMP" align="right"><?php echo $empart ?>€</span><?php } } } else { if($campart > 0) { if($validadeart > '0000-00-00') { if(strtotime($datahj) <= strtotime($validadeart)) { ?> <span class="prod-desconto"><?php echo $totali->desconto($campart, $pvpart); ?>%</span><p></p> <span class="precoOld"><?php echo $pvpart ?>€</span><br /> <span class="precoPVP" align="right"><?php echo $campart ?>€</span><br /> <!--<span class="precoIVA">c/ iva <b><u><?php echo $totali->calculaivass($ivaart, $campart); ?>€</u></b></span>--> <?php } else { ?> <br /><br /> <span class="precoPVP" align="right"><?php echo $pvpart ?>€</span><br /> <!--<span class="precoIVA">c/ iva <b><u><?php echo $totali->calculaivass($ivaart, $pvpart); ?>€</u></b></span>--><?php } } else { ?> <br /><br /> <span class="precoPVP" align="right"><?php echo $pvpart ?>€</span><br /> <!--<span class="precoIVA">c/ iva <b><u><?php echo $totali->calculaivass($ivaart, $pvpart); ?>€</u></b></span>--><?php } } else { ?> <br /><br /> <span class="precoPVP" align="right"><?php echo $pvpart ?>€</span><br /> <!--<span class="precoIVA">c/ iva <b><u><?php echo $totali->calculaivass($ivaart, $pvpart); ?>€</u></b></span>--><?php } } ?> </div> <div id="add"> <form action="AddArtcarrinho.php?<?php echo $SID ?>" method="post" name="comprar"> <input name="ref" type="hidden" value="<?php echo $refart ?>" /> <input name="desc" type="hidden" value="<?php echo $descart ?>" /> <input name="quantidade" type="hidden" value="1" /> <!--<input type="image" class="imagem-carrinho" src="images/cart2.png" value="Comprar2" width="0" height="0" title="Comprar este artigo" name="Comprar2"/>--> <span class="qtdpesq">Qtd : </span> <input name="qtds" value="1" type="text" id="qtds" class="caixatqtd" title="Insira uma quantidade" maxlength="5" onkeypress="return numbersonly(this, event)" /> <input type="image" src="../images/webbuttons.png" value="Comprar4" name="Comprar4" alt="Comprar4" title="Comprar : <?php echo ucwords(strtolower($descart)) ?>" width="105" height="28" style="vertical-align:bottom; margin:0;"/> </form> </div> </div> <?php if ($i == 5) { $i = 0; ?></div><?php } } } else { ?><div>Não foram encontrados resultados</div><?php } ?> </div> </div> Edited May 19, 2014 at 03:13 PM by JFernandesVR
bioshock Posted May 19, 2014 at 03:42 PM Report #556274 Posted May 19, 2014 at 03:42 PM Podes utilizar o mod. Exemplo prático: for($i = 0; $i <= 10; $i++){ if(($i % 5) == 0){ echo "<div id='linha:" . $i . "' style='border: 1px solid #000'>"; } echo "<div> Produto:" . $i . "</div>"; if(($i % 5) == 0){ echo "</div>"; } }
JFernandesVR Posted May 19, 2014 at 04:04 PM Author Report #556278 Posted May 19, 2014 at 04:04 PM Podes utilizar o mod. Exemplo prático: for($i = 0; $i <= 10; $i++){ if(($i % 5) == 0){ echo "<div id='linha:" . $i . "' style='border: 1px solid #000'>"; } echo "<div> Produto:" . $i . "</div>"; if(($i % 5) == 0){ echo "</div>"; } } isso é para por dentro do while? apliquei isso e ele repete cada artigo 5 vezes. ou seja, 1 linha para cada artigo e emvez de por 5 artigos numa linha, repete o mesmo artigo 5 vezes
bioshock Posted May 19, 2014 at 05:05 PM Report #556283 Posted May 19, 2014 at 05:05 PM (edited) O teu código está uma confusão como deves calcular, mas se queres utilizar dentro do ciclo while tens de alterar algumas coisas. $i = 0; while ($list = mysql_fetch_array($rs2)) $i++; if(($i % 5) == 0){ echo "<div id='linha:" . $i . "' style='border: 1px solid #000'>"; } echo "<div> Produto:" . $i . "</div>"; if(($i % 5) == 0){ echo "</div>"; } } Edited May 19, 2014 at 05:05 PM by bioshock
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now