japa100 0 Denunciar post Postado Outubro 18, 2012 <?php require_once("conn.php"); require_once("header.php"); //get 3 random products $q1 = "select devbg_products.*, devbg_categories.*, devbg_subcategories.* from devbg_products left join devbg_categories on devbg_products.ItemCategory = devbg_categories.CategoryID left join devbg_subcategories on devbg_products.ItemSubcategory = devbg_subcategories.SubcategoryID order by rand() limit 0,6 "; $r1 = mysql_query($q1) or die(mysql_error()); if(mysql_num_rows($r1) == '0') { $NoItems = "<center>Sem Itens Ainda</center>"; } else { while($a1 = mysql_fetch_array($r1)) { $MyPrice = number_format($a1[itemPrice], 2, ".", ""); if(!empty($a1[itemImage])) { $xy = @getimagesize("items_images/$a1[itemImage]"); $x = $xy[0]; $y = $xy[1]; $NewItemName = str_replace("'", "", $a1[itemName]); $DisplayImage = "<a href=\"javascript:ShowPic('items_images/$a1[itemImage]', '$NewItemName', '$x', '$y');\"><img src=\"items_images/$a1[itemImage]\" width=100 alt=\"$a1[itemName]\" border=0 style=\"border-color:black\"></a>"; } else { $DisplayImage = " "; } $DisplayIndex .= " <table align=center width=300 border=0 rules=rows cellspacing=0 bordercolor=black> <tr> <td valign=top width=140>$DisplayImage</td> <td width=160 valign=top> <a class=\"ItemTitle\" href=\"ViewItem.php?ItemID=$a1[itemID]\">$a1[itemName]</a> <br><BR> <font color=black face=verdana size=1><b>Categoria: </b></font><a class=\"CategoryClass\" href=\"ShowCategory.php?CategoryID=$a1[itemCategory]\">$a1[CategoryName]</a>"; if(!empty($a1[subcategoryID])) { $DisplayIndex .= ", <a class=\"SubcategoryClass\" href=\"ShowCategory.php?CategoryID=$a1[itemCategory]&SubcategoryID=$a1[itemSubcategory]\">$a1[subcategoryName]</a>"; } $DisplayIndex .= " <br> <font color=red face=verdana size=2><b>preço: R$ $MyPrice</b></font> <br><br> <form method=post action=add.php style=\"margin:0\"> <input type=hidden name=ItemID value=\"$a1[itemID]\"> <input type=hidden name=ItemName value=\"$a1[itemName]\"> <input type=hidden name=ItemShipping value=\"$a1[itemShipping]\"> <input type=hidden name=ItemPrice value=\"$MyPrice\"> <input type=submit name=s1 value=\"Comprar\" class=sub> </form> </td> </tr> </table><br><hr size=1 color=E3E3E3>"; } } if(isset($NoItems)) { echo $NoItems; } else { require_once("templates/IndexTemplate.php"); } require_once("footer.php"); ?> Compartilhar este post Link para o post Compartilhar em outros sites
Wingdings 20 Denunciar post Postado Outubro 18, 2012 Ta, mas qual a duvida? Apresenta algum erro? O que você esta tentando fazer? de mais detalhes :thumbsup: Compartilhar este post Link para o post Compartilhar em outros sites
japa100 0 Denunciar post Postado Outubro 18, 2012 Ta, mas qual a duvida? Apresenta algum erro? O que você esta tentando fazer? de mais detalhes :thumbsup: Olá, Não existe erros eu só precisava alterar o modo de exibição tipo mostrar em linhas e colunas, assim tah mostrando em linhas uma abaixo da outra e eu queria que mostrasse em 3 colunas respeitando a quantidade de linhas definida por mim. entende? Compartilhar este post Link para o post Compartilhar em outros sites
Wingdings 20 Denunciar post Postado Outubro 18, 2012 Esse trecho do código você poe antes do laço de repetição <table align=center width=300 border=0 rules=rows cellspacing=0 bordercolor=black> <tr> e esse depois do laço </tr> </table> Assim, você pode criar um contador Ex.: $cont = 0; $num_col = 3; //Numero de colunas que você vai querer ter Com isso, você pode fazer uma comparação, que a cada 3 registros exibidos, joga um </tr><tr> na tela e zera o contador, entendeu? if($cont == $num_col){ echo "</tr><tr>"; $cont = 0; } else { $cont++ } Compartilhar este post Link para o post Compartilhar em outros sites
japa100 0 Denunciar post Postado Outubro 18, 2012 Ai que droga eu não tenho muito conhecimento em php não consegui tem como editar o codigo pra mim? fazendo favor Compartilhar este post Link para o post Compartilhar em outros sites
Wingdings 20 Denunciar post Postado Outubro 18, 2012 Tenta assim, nao posso testar :S <?php require_once("conn.php"); require_once("header.php"); //get 3 random products $q1 = "select devbg_products.*, devbg_categories.*, devbg_subcategories.* from devbg_products left join devbg_categories on devbg_products.ItemCategory = devbg_categories.CategoryID left join devbg_subcategories on devbg_products.ItemSubcategory = devbg_subcategories.SubcategoryID order by rand() limit 0,6 "; $r1 = mysql_query($q1) or die(mysql_error()); if(mysql_num_rows($r1) == '0') { $NoItems = "<center>Sem Itens Ainda</center>"; } else { echo "<table align=center width=300 border=0 rules=rows cellspacing=0 bordercolor=black> <tr> "; $cont = 0; $num_col = 3; //Numero de colunas que você vai querer ter while($a1 = mysql_fetch_array($r1)) { $MyPrice = number_format($a1[itemPrice], 2, ".", ""); if(!empty($a1[itemImage])) { $xy = @getimagesize("items_images/$a1[itemImage]"); $x = $xy[0]; $y = $xy[1]; $NewItemName = str_replace("'", "", $a1[itemName]); $DisplayImage = "<a href=\"javascript:ShowPic('items_images/$a1[itemImage]', '$NewItemName', '$x', '$y');\"><img src=\"items_images/$a1[itemImage]\" width=100 alt=\"$a1[itemName]\" border=0 style=\"border-color:black\"></a>"; } else { $DisplayImage = " "; } if($cont == $num_col){ echo "</tr><tr>"; $cont = 0; } else { $cont++; } $DisplayIndex .= " <td valign=top width=140>$DisplayImage</td> <td width=160 valign=top> <a class=\"ItemTitle\" href=\"ViewItem.php?ItemID=$a1[itemID]\">$a1[itemName]</a> <br><BR> <font color=black face=verdana size=1><b>Categoria: </b></font><a class=\"CategoryClass\" href=\"ShowCategory.php?CategoryID=$a1[itemCategory]\">$a1[CategoryName]</a>"; if(!empty($a1[subcategoryID])) { $DisplayIndex .= ", <a class=\"SubcategoryClass\" href=\"ShowCategory.php?CategoryID=$a1[itemCategory]&SubcategoryID=$a1[itemSubcategory]\">$a1[subcategoryName]</a>"; } $DisplayIndex .= " <br> <font color=red face=verdana size=2><b>preço: R$ $MyPrice</b></font> <br><br> <form method=post action=add.php style=\"margin:0\"> <input type=hidden name=ItemID value=\"$a1[itemID]\"> <input type=hidden name=ItemName value=\"$a1[itemName]\"> <input type=hidden name=ItemShipping value=\"$a1[itemShipping]\"> <input type=hidden name=ItemPrice value=\"$MyPrice\"> <input type=submit name=s1 value=\"Comprar\" class=sub> </form> </td> "; } echo "</tr></table>"; } if(isset($NoItems)) { echo $NoItems; } else { require_once("templates/IndexTemplate.php"); } require_once("footer.php"); ?> Compartilhar este post Link para o post Compartilhar em outros sites
japa100 0 Denunciar post Postado Outubro 18, 2012 O jeito acima ta repondendo pela ( order by rand() limit 0,6 ";) que ja foi definido para seis linha. Agora esta me mostrando uma unica linha com 6 colunas e não adianta eu mudar o ($num_col = 3; ) por que esta respeitando o que foi definido acima. se eu diminuir o valor de 0,6 para 0,5 ela me mostra 5 colunas ma mesma linha. entende? Compartilhar este post Link para o post Compartilhar em outros sites
Wingdings 20 Denunciar post Postado Outubro 18, 2012 sim sim por erro meu, desculpe >.< } else { $cont++; } Onde esta esse trecho do codigo, altere para } $cont++; Assim acho que vai funcionar 100% :thumbsup: Compartilhar este post Link para o post Compartilhar em outros sites
japa100 0 Denunciar post Postado Outubro 18, 2012 Mudei conforme você me falou e ainda continua com o mesmo erro :cry: Compartilhar este post Link para o post Compartilhar em outros sites
Wingdings 20 Denunciar post Postado Outubro 18, 2012 ao enves de echo tente $DisplayIndex .= if($cont == $num_col){ $DisplayIndex .= "</tr><tr>"; $cont = 0; } $cont++; Compartilhar este post Link para o post Compartilhar em outros sites
japa100 0 Denunciar post Postado Outubro 18, 2012 Agora deu certo :grin: mais na primeira linha ela esta fora da demais já mudei o ( echo "<table align=center width=300 border=0 rules=rows cellspacing=0 bordercolor=black> ) para left e não alinha, o que será que ouve? porque sera que não alinha Compartilhar este post Link para o post Compartilhar em outros sites
Wingdings 20 Denunciar post Postado Outubro 18, 2012 esta faltando as aspas não é? echo "<table align=\"center\" width=\"300\" border=\"0\" rules=\"rows\" cellspacing=\"0\" bordercolor=\"black\">"; ou echo '<table align="center" width="300" border="0" rules="rows" cellspacing="0" bordercolor="black">'; Compartilhar este post Link para o post Compartilhar em outros sites
japa100 0 Denunciar post Postado Outubro 18, 2012 Troquei o echo pelo $DisplayIndex .= deu certo Compartilhar este post Link para o post Compartilhar em outros sites
Wingdings 20 Denunciar post Postado Outubro 18, 2012 :thumbsup: o importante é você entender tbm o codigo e vejo que você ta pegando o jeito :P Compartilhar este post Link para o post Compartilhar em outros sites
japa100 0 Denunciar post Postado Outubro 18, 2012 Eu usei o mesmo esquema nesse codigo só que percebi que tenho paginaçao pode me ajudar? <? require_once("conn.php"); require_once("header.php"); if(!empty($_GET[start])) { $Start = $_GET[start]; } else { $Start = '0'; } $ByPage = "10"; if(empty($_GET[subcategoryID])) { $q1 = "select devbg_products.*, devbg_categories.*, devbg_subcategories.* from devbg_products left join devbg_categories on devbg_products.ItemCategory = devbg_categories.CategoryID left join devbg_subcategories on devbg_products.ItemSubcategory = devbg_subcategories.SubcategoryID where devbg_products.ItemCategory = '$_GET[CategoryID]' order by ItemName limit $Start, $ByPage"; $qnav = "select devbg_products.*, devbg_categories.*, devbg_subcategories.* from devbg_products left join devbg_categories on devbg_products.ItemCategory = devbg_categories.CategoryID left join devbg_subcategories on devbg_products.ItemSubcategory = devbg_subcategories.SubcategoryID where devbg_products.ItemCategory = '$_GET[CategoryID]' "; } else { $q1 = "select devbg_products.*, devbg_categories.*, devbg_subcategories.* from devbg_products left join devbg_categories on devbg_products.ItemCategory = devbg_categories.CategoryID left join devbg_subcategories on devbg_products.ItemSubcategory = devbg_subcategories.SubcategoryID where devbg_products.ItemCategory = '$_GET[CategoryID]' and devbg_products.ItemSubcategory = '$_GET[subcategoryID]' order by ItemName limit $Start, $ByPage"; $qnav = "select devbg_products.*, devbg_categories.*, devbg_subcategories.* from devbg_products left join devbg_categories on devbg_products.ItemCategory = devbg_categories.CategoryID left join devbg_subcategories on devbg_products.ItemSubcategory = devbg_subcategories.SubcategoryID where devbg_products.ItemCategory = '$_GET[CategoryID]' and devbg_products.ItemSubcategory = '$_GET[subcategoryID]' "; } $r1 = mysql_query($q1) or die(mysql_error()); if(mysql_num_rows($r1) == '0') { $NoItems = "<center>There are no items at this category!</center>"; } else { $DisplayCategory .= "<table align=center width=300 border=0 rules=rows cellspacing=0 bordercolor=black> <tr> "; $cont = 0; $num_col = 2; //Numero de colunas que você vai querer ter while($a1 = mysql_fetch_array($r1)) { $MyPrice = number_format($a1[itemPrice], 2, ".", ""); if(!empty($a1[itemImage])) { $xy = getimagesize("items_images/$a1[itemImage]"); $x = $xy[0]; $y = $xy[1]; $NewItemName = str_replace("'", "", $a1[itemName]); $DisplayImage = "<a href=\"javascript:ShowPic('items_images/$a1[itemImage]', '$NewItemName', '$x', '$y');\"><img src=\"items_images/$a1[itemImage]\" width=100 alt=\"$a1[itemName]\" border=0 style=\"border-color:black\"></a>"; } else { $DisplayImage = " "; } if($cont == $num_col){ $DisplayCategory .= "</tr><tr>"; $cont = 0; } $cont++; $DisplayCategory .= " <td valign=top width=140>$DisplayImage</td> <td width=160 valign=top> <a class=\"ItemTitle\" href=\"ViewItem.php?ItemID=$a1[itemID]\">$a1[itemName]</a><BR> <br> <font color=black face=verdana size=1><b>Categoria: </b></font><a class=\"CategoryClass\" href=\"ShowCategory.php?CategoryID=$a1[itemCategory]\">$a1[CategoryName]</a>"; if(!empty($a1[subcategoryID])) { $DisplayCategory .= ", <a class=\"SubcategoryClass\" href=\"ShowCategory.php?CategoryID=$a1[itemCategory]&SubcategoryID=$a1[itemSubcategory]\">$a1[subcategoryName]</a>"; } $DisplayCategory .= " <br> <font color=red face=verdana size=2><b>Preço: R$$MyPrice</b></font> <br><br> <form method=post action=add.php style=\"margin:0\"> <input type=hidden name=ItemID value=\"$a1[itemID]\"> <input type=hidden name=ItemName value=\"$a1[itemName]\"> <input type=hidden name=ItemShipping value=\"$a1[itemShipping]\"> <input type=hidden name=ItemPrice value=\"$MyPrice\"> <input type=submit name=s1 value=\"Comprar\" class=sub> </form> </td> </tr> </table><br><hr size=1 color=E3E3E3>"; } //build the "next" - "prev" navigatioin $rnav = mysql_query($qnav) or die(mysql_error()); $rows = mysql_num_rows($rnav); if($rows > $ByPage) { $NextPrev = "<br><table align=center>"; $NextPrev .= "<td align=center><font face=verdana size=2> | "; $pages = ceil($rows/$ByPage); for($i = 0; $i <= ($pages); $i++) { $PageStart = $ByPage*$i; $i2 = $i + 1; if($PageStart == $Start) { $links[] = " <span class=DNav>$i2</span>\n\t "; } elseif($PageStart < $rows) { $links[] = " <a class=Nav href=ShowCategory.php?Start=$PageStart&ByPage=$ByPage&CategoryID=$_GET[CategoryID]&SubcategoryID=$_GET[subcategoryID]>$i2</a>\n\t "; } } $links2 = implode(" | ", $links); $NextPrev .= $links2; $NextPrev .= "| </td>"; $NextPrev .= "</table><br>\n"; } } if(isset($NoItems)) { echo $NoItems; } else { require_once("templates/ShowCategoryTemplate.php"); } require_once("footer.php"); ?> Compartilhar este post Link para o post Compartilhar em outros sites