chris2010 Posted July 4, 2010 Share Posted July 4, 2010 i got a php script that list a row of items up to 6 in a single row from mysql and but i would like it to display two side by side and then make a new row and list two side by side again. "this for an online store" could any help im not that good at php or mysql i also up load a photo of why it list the data now here my code for viewitems.php http://pastebin.com/tfdAB67U and for the template for viewitems.php http://pastebin.com/LYyxV7rR [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/206672-phpmysql-help/ Share on other sites More sharing options...
scaleautostyle Posted July 4, 2010 Share Posted July 4, 2010 can you shw your code... it will be easier to help you yours sebastien Quote Link to comment https://forums.phpfreaks.com/topic/206672-phpmysql-help/#findComment-1080977 Share on other sites More sharing options...
wildteen88 Posted July 4, 2010 Share Posted July 4, 2010 To display results in multiple columns have a look at this FAQ. Quote Link to comment https://forums.phpfreaks.com/topic/206672-phpmysql-help/#findComment-1080989 Share on other sites More sharing options...
isedeasy Posted July 4, 2010 Share Posted July 4, 2010 I would just float the items left and give them a width of half the container Quote Link to comment https://forums.phpfreaks.com/topic/206672-phpmysql-help/#findComment-1080991 Share on other sites More sharing options...
chris2010 Posted July 4, 2010 Author Share Posted July 4, 2010 can you shw your code... it will be easier to help you yours sebastien the is here for viewitems.php http://pastebin.com/tfdAB67U and for the template for viewitems.php http://pastebin.com/LYyxV7rR Quote Link to comment https://forums.phpfreaks.com/topic/206672-phpmysql-help/#findComment-1081079 Share on other sites More sharing options...
chris2010 Posted July 4, 2010 Author Share Posted July 4, 2010 I would just float the items left and give them a width of half the container how would i do this i dont know mach about php or mysql and is it hard to do? Quote Link to comment https://forums.phpfreaks.com/topic/206672-phpmysql-help/#findComment-1081081 Share on other sites More sharing options...
chris2010 Posted July 4, 2010 Author Share Posted July 4, 2010 To display results in multiple columns have a look at this FAQ. how can i put this code in my soo it do what i need, chould some show me how to or put it in if it aint much trouble <?php $cols = 0; echo "<table><tr>"; while ($cols < 20) { echo ($cols % 2 == 0)? "</tr><tr>" : ""; echo "<td>$cols</td>"; $cols++; } echo "</tr></table>" ?> Quote Link to comment https://forums.phpfreaks.com/topic/206672-phpmysql-help/#findComment-1081088 Share on other sites More sharing options...
GetFreaky Posted July 5, 2010 Share Posted July 5, 2010 Actually its quite a simple process OP. Here is a better explaination of the "%" operator. http://www.devchunks.com/arithmetic/using-the-php-modulus-operator/ Quote Link to comment https://forums.phpfreaks.com/topic/206672-phpmysql-help/#findComment-1081117 Share on other sites More sharing options...
chris2010 Posted July 5, 2010 Author Share Posted July 5, 2010 Actually its quite a simple process OP. Here is a better explaination of the "%" operator. http://www.devchunks.com/arithmetic/using-the-php-modulus-operator/ ]thank for ur reply i try to put this in the code but dont have a cule where it gos and im think of just giveing up on it thank u for ur help and the link Quote Link to comment https://forums.phpfreaks.com/topic/206672-phpmysql-help/#findComment-1081131 Share on other sites More sharing options...
chris2010 Posted July 5, 2010 Author Share Posted July 5, 2010 sorry i give the wrong code here the right code it wasen viewitem.php i mant put the code up for ShowCategory.php i had to made pages open when i did this post and i lost track sorry. ShowCategory.php that show the products <? 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 { 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 class=\"ItemTitle\" href=\"ViewItem.php?CategoryID=$a1[itemCategory]&ItemID=$a1[itemID]\"><img src=\"items_images/$a1[itemImage]\" width=100 alt=\"$a1[itemName]\" border=0 style=\"border-color:black\"></a>"; } else { $DisplayImage = " "; } $DisplayCategory .= " <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?CategoryID=$a1[itemCategory]&ItemID=$a1[itemID]\">$a1[itemName]</a><BR> <br> <font color=black face=verdana size=1><b>Category: </b></font><a class=\"CategoryClass\" href=\"ShowCategory.php?CategoryID=$a1[itemCategory]\">$a1[CategoryName]</a>"; if(!empty($a1[subcategoryID])) { $DisplayCategory .= "<br><font color=black face=verdana size=1><b>Subcategory: </b></font><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>Color: $a1[Color]</b></font> <br> <font color=red face=verdana size=2><b>Size: $a1[size]</b></font> <br> <font color=red face=verdana size=2><b>Price: $$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=\"Add to card\" 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 width=600>"; $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"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/206672-phpmysql-help/#findComment-1081188 Share on other sites More sharing options...
chris2010 Posted July 5, 2010 Author Share Posted July 5, 2010 i had post of this befor but i give the wrong code sorry for that here is the right one. thank you all for you help in here. i got a php script that list a row of items up to 6 in a single row from mysql and but i would like it to display two side by side and then make a new row and list two side by side again. "this for an online store" could any help im not that good at php or mysql i also up load a photo of why it list the data now here my code ShowCategory.php <? require_once("conn.php"); require_once("header.php"); if(!empty($_GET[start])) { $Start = $_GET[start]; } else { $Start = '0'; } $ByPage = "5"; 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 { 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 class=\"ItemTitle\" href=\"ViewItem.php?CategoryID=$a1[itemCategory]&ItemID=$a1[itemID]\"><img src=\"items_images/$a1[itemImage]\" width=100 alt=\"$a1[itemName]\" border=0 style=\"border-color:black\"></a>"; } else { $DisplayImage = " "; } $DisplayCategory .= " <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?CategoryID=$a1[itemCategory]&ItemID=$a1[itemID]\">$a1[itemName]</a><BR> <br> <font color=black face=verdana size=1><b>Category: </b></font><a class=\"CategoryClass\" href=\"ShowCategory.php?CategoryID=$a1[itemCategory]\">$a1[CategoryName]</a>"; if(!empty($a1[subcategoryID])) { $DisplayCategory .= "<br><font color=black face=verdana size=1><b>Subcategory: </b></font><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>Color: $a1[Color]</b></font> <br> <font color=red face=verdana size=2><b>Size: $a1[size]</b></font> <br> <font color=red face=verdana size=2><b>Price: $$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=\"Add to card\" 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 width=600>"; $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"); ?> [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/206672-phpmysql-help/#findComment-1081191 Share on other sites More sharing options...
phpSensei Posted July 5, 2010 Share Posted July 5, 2010 I cant use your code because its too large and messy to comprehend no offense, here is an example that might be more clear /// so lets start a new query $sql = mysql_query("...."); // dont feel like typing it in haha /// How many columns you want $columns = 2; /// Heres our counter thingy incrementer $i = 0; // Create the while loop while($row = mysql_fetch_array($sql)){ if($i == 0){ print "<tr>"; // okay so open row if the $i hasnt reach 2 yet } print "<td>".$row['somefield']."</td>"; // this is your data your printing off if($i == $columns){ print "</tr>"; // our $i has reach the maximum amount of columns, so close the row and start a new $i = 0; //reset the increment } $i++; } Quote Link to comment https://forums.phpfreaks.com/topic/206672-phpmysql-help/#findComment-1081194 Share on other sites More sharing options...
phpSensei Posted July 5, 2010 Share Posted July 5, 2010 Sorry, I added some more to the code, review my post. Quote Link to comment https://forums.phpfreaks.com/topic/206672-phpmysql-help/#findComment-1081195 Share on other sites More sharing options...
phpSensei Posted July 5, 2010 Share Posted July 5, 2010 Also ADD this to the end of your script if($i < $columns){ for($j=$i; $j<$max_columns;$j++) echo "<td> </td>";} ?> or as a possible alternative would be <?php $cols = 0; echo "<table><tr>"; while ($cols < 20) { echo ($cols % 3 == 0)? "</tr><tr>" : ""; echo "<td>$cols</td>"; $cols++; } echo "</tr></table>";?> Quote Link to comment https://forums.phpfreaks.com/topic/206672-phpmysql-help/#findComment-1081200 Share on other sites More sharing options...
chris2010 Posted July 5, 2010 Author Share Posted July 5, 2010 i never wrote the code , and its ok , i try doing what u said i still cant get it to work the page dont show anything when i put the code where i things it gos while($a1 = mysql_fetch_array($r1)) { if($i == 0){ if($i == $columns){ $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 class=\"ItemTitle\" href=\"ViewItem.php?CategoryID=$a1[itemCategory]&ItemID=$a1[itemID]\"><img src=\"items_images/$a1[itemImage]\" width=100 alt=\"$a1[itemName]\" border=0 style=\"border-color:black\"></a>"; } else { $DisplayImage = " "; } $DisplayCategory .= " <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?CategoryID=$a1[itemCategory]&ItemID=$a1[itemID]\">$a1[itemName]</a><BR><br> <font color=black face=verdana size=1><b>Category: </b></font><a class=\"CategoryClass\" href=\"ShowCategory.php?CategoryID=$a1[itemCategory]\">$a1[CategoryName]</a>"; if(!empty($a1[subcategoryID])) { $DisplayCategory .= "<br><font color=black face=verdana size=1><b>Subcategory: </b></font><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>Color: $a1[Color]</b></font> <br> <font color=red face=verdana size=2><b>Size: $a1[size]</b></font> <br> <font color=red face=verdana size=2><b>Price: $$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=\"Add to card\" class=sub> </form> </td> </tr> </table><br><hr size=1 color=E3E3E3>"; } $i = 0; //reset the increment } $i++; } Quote Link to comment https://forums.phpfreaks.com/topic/206672-phpmysql-help/#findComment-1081208 Share on other sites More sharing options...
phpSensei Posted July 5, 2010 Share Posted July 5, 2010 i never wrote the code , and its ok , i try doing what u said i still cant get it to work the page dont show anything when i put the code where i things it gos while($a1 = mysql_fetch_array($r1)) { if($i == 0){ if($i == $columns){ $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 class=\"ItemTitle\" href=\"ViewItem.php?CategoryID=$a1[itemCategory]&ItemID=$a1[itemID]\"><img src=\"items_images/$a1[itemImage]\" width=100 alt=\"$a1[itemName]\" border=0 style=\"border-color:black\"></a>"; } else { $DisplayImage = " "; } $DisplayCategory .= " <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?CategoryID=$a1[itemCategory]&ItemID=$a1[itemID]\">$a1[itemName]</a><BR><br> <font color=black face=verdana size=1><b>Category: </b></font><a class=\"CategoryClass\" href=\"ShowCategory.php?CategoryID=$a1[itemCategory]\">$a1[CategoryName]</a>"; if(!empty($a1[subcategoryID])) { $DisplayCategory .= "<br><font color=black face=verdana size=1><b>Subcategory: </b></font><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>Color: $a1[Color]</b></font> <br> <font color=red face=verdana size=2><b>Size: $a1[size]</b></font> <br> <font color=red face=verdana size=2><b>Price: $$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=\"Add to card\" class=sub> </form> </td> </tr> </table><br><hr size=1 color=E3E3E3>"; } $i = 0; //reset the increment } $i++; } Sorry I forgot a closing brack after the IF($i==0){ Its not if($i == 0){ if($i == $columns){ But you didn't follow my example... Review your code and mine, and you'll what i mean. Quote Link to comment https://forums.phpfreaks.com/topic/206672-phpmysql-help/#findComment-1081220 Share on other sites More sharing options...
chris2010 Posted July 5, 2010 Author Share Posted July 5, 2010 But you didn't follow my example... Review your code and mine, and you'll what i mean. i try to follow ypur example and i look over myay code and ur and i dont get it or understand it at all it my first time trying to edit this coding. do you know of some one who can fix it for a low cost?. again thank you for helpin Quote Link to comment https://forums.phpfreaks.com/topic/206672-phpmysql-help/#findComment-1081229 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.