jacko_162 Posted January 6, 2008 Share Posted January 6, 2008 i have the following code; <? // Query to pull information from the "products" Database $result = mysql_query("select * from $table1 order by id DESC LIMIT 0 , 8"); while ($row = mysql_fetch_object($result)) { ?> <table width="100%" height="75" border="0" cellspacing="1" cellpadding="3"> <tr> <td width="113" height="78" valign="top"> <div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><a href="../product.php?ID=<? echo $row->id; ?>"><img src="../images/products/<? echo $row->id; ?>thumb.jpg" border="0" style="border: 1px solid #35830C" width="113" height="75"></a></font></div></td> <td valign="top"><div align="left"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><a href="../product.php?ID=<? echo $row->id; ?>"><? echo $row->name; ?><br /> </a>Product code: <? echo $row->id; ?></font><strong><br /> <br /> <br /> £<? echo $row->price; ?></strong></div></td> </tr> </table> <br /> <? } ?> it pulls products from my database but lists them going down the page?! how can i make it into a grid like view but limit the products to a maximum of 3 products per row and a total of 12 products? any help would be appreciated.?! Quote Link to comment https://forums.phpfreaks.com/topic/84755-solved-quick-layout-problem/ Share on other sites More sharing options...
revraz Posted January 6, 2008 Share Posted January 6, 2008 http://www.phpfreaks.com/forums/index.php/topic,95426.0.html Quote Link to comment https://forums.phpfreaks.com/topic/84755-solved-quick-layout-problem/#findComment-431892 Share on other sites More sharing options...
jacko_162 Posted January 6, 2008 Author Share Posted January 6, 2008 i treid to reproduce that but cant get it to output anything?! just outputs a blank page? no errors? Quote Link to comment https://forums.phpfreaks.com/topic/84755-solved-quick-layout-problem/#findComment-431897 Share on other sites More sharing options...
revraz Posted January 6, 2008 Share Posted January 6, 2008 Usually means you have a error in your code. Quote Link to comment https://forums.phpfreaks.com/topic/84755-solved-quick-layout-problem/#findComment-431900 Share on other sites More sharing options...
jacko_162 Posted January 6, 2008 Author Share Posted January 6, 2008 i fond a chunk of code to use; <title>Control Panel - Home</title> <? include("includes/header.php") ?> <table width=300 border=0 align=center> <?php //set 3 to 4 of you want 4 columns. Set it to 5 if you want 5, etc $numcols = 5; // how many columns to display $numcolsprinted = 0; // no of columns so far // get the results to be displayed $query = "SELECT * FROM $table1 ORDER BY id"; $mysql_result = mysql_query($query); // get each row while($myrow = mysql_fetch_assoc($mysql_result)) { // set rows you want to view here $id = $myrow['id']; if ($numcolsprinted == $numcols) { print "</tr>\n<tr>\n"; $numcolsprinted = 0; } // output row from database echo "<td>$id</td>\n"; // bump up row counter $numcolsprinted++; } // end while loop $colstobalance = $numcols - $numcolsprinted; for ($i=1; $i<=$colstobalance; $i++) { } print "<TD></TD>\n"; ?> </table> can i edit; // output row from database echo "<td>$id</td>\n"; to ouput it like this; <? // Query to pull information from the "products" Database $result = mysql_query("select * from $table1 order by id DESC LIMIT 0 , 8"); while ($row = mysql_fetch_object($result)) { ?><table width="100%" height="75" border="0" cellspacing="1" cellpadding="3"> <tr> <td width="113" height="78" valign="top"> <div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><a href="../product.php?ID=<? echo $row->id; ?>"><img src="../images/products/<? echo $row->id; ?>thumb.jpg" border="0" style="border: 1px solid #35830C" width="113" height="75"></a></font></div> </td> <td valign="top"><div align="left"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><a href="../product.php?ID=<? echo $row->id; ?>"><? echo $row->name; ?><br /> </a>Product code: <? echo $row->id; ?></font><strong><br /> <br /> <br /> £<? echo $row->price; ?></strong></div></td> </tr> </table> <br /> <? } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84755-solved-quick-layout-problem/#findComment-431926 Share on other sites More sharing options...
redarrow Posted January 6, 2008 Share Posted January 6, 2008 why not do it manualy <?php $word=array("one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","therteen"); echo"<table border='4'><tr><td>$word[0]<br>$word[1]<br>$word[2]<td></tr></table> <br><br>"; echo"<table border='4'><tr><td>$word[3]<br>$word[4]<br>$word[5]<td></tr></table> <br><br>"; echo"<table border='4'><tr><td>$word[6]<br>$word[7]<br>$word[8]<td></tr></table> <br><br>"; echo"<table border='4'><tr><td>$word[9]<br>$word[10]<br>$word[11]<td></tr></table> <br><br>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/84755-solved-quick-layout-problem/#findComment-431974 Share on other sites More sharing options...
kratsg Posted January 6, 2008 Share Posted January 6, 2008 Are you saying you want to display 12 products per page or just the first 12 products that show up? Quote Link to comment https://forums.phpfreaks.com/topic/84755-solved-quick-layout-problem/#findComment-431976 Share on other sites More sharing options...
jacko_162 Posted January 6, 2008 Author Share Posted January 6, 2008 i want to display the latest 12 products added. in rows of 3.! Quote Link to comment https://forums.phpfreaks.com/topic/84755-solved-quick-layout-problem/#findComment-432080 Share on other sites More sharing options...
revraz Posted January 6, 2008 Share Posted January 6, 2008 Why do you have the LIMIT set to 8? Quote Link to comment https://forums.phpfreaks.com/topic/84755-solved-quick-layout-problem/#findComment-432086 Share on other sites More sharing options...
jacko_162 Posted January 6, 2008 Author Share Posted January 6, 2008 i have limit set to 8 at moment cause it lists the ID desending and cause it goes from top to bottom in a list, if i can arrange it in rows then i can display more. im new to php so forgive me if i dont fully understand yet.. this image shows what i need it to do; i have them listed on the right already, but i need them like they are in the middle of the image... Quote Link to comment https://forums.phpfreaks.com/topic/84755-solved-quick-layout-problem/#findComment-432100 Share on other sites More sharing options...
Ken2k7 Posted January 6, 2008 Share Posted January 6, 2008 Something like this? <table width="100%" height="75" border="0" cellspacing="1" cellpadding="3"><tr> <?php // Query to pull information from the "products" Database $result = mysql_query("select * from $table1 order by id DESC LIMIT 0 , 8"); /* edited below: added 2 lines */ $row_number = 4; $counter = 0; while ($row = mysql_fetch_object($result)) { if ($counter%$row_number==0&&$counter!=0) echo "</tr><tr>"; ?> <td width="113" height="78" valign="top"> <div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><a href="../product.php?ID=<?php echo $row->id; ?>"><img src="../images/products/<?php echo $row->id; ?>thumb.jpg" border="0" style="border: 1px solid #35830C" width="113" height="75"></a></font></div> </td> <td valign="top"><div align="left"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><a href="../product.php?ID=<?php echo $row->id; ?>"><?php echo $row->name; ?><br /> </a>Product code: <?php echo $row->id; ?></font><strong><br /> <br /> <br /> £<?php echo $row->price; ?></strong></div></td> <?php } ?> </tr> </table> <br /> Quote Link to comment https://forums.phpfreaks.com/topic/84755-solved-quick-layout-problem/#findComment-432122 Share on other sites More sharing options...
jacko_162 Posted January 6, 2008 Author Share Posted January 6, 2008 Something like this? <table width="100%" height="75" border="0" cellspacing="1" cellpadding="3"><tr> <?php // Query to pull information from the "products" Database $result = mysql_query("select * from $table1 order by id DESC LIMIT 0 , 8"); /* edited below: added 2 lines */ $row_number = 4; $counter = 0; while ($row = mysql_fetch_object($result)) { if ($counter%$row_number==0&&$counter!=0) echo "</tr><tr>"; ?> <td width="113" height="78" valign="top"> <div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><a href="../product.php?ID=<?php echo $row->id; ?>"><img src="../images/products/<?php echo $row->id; ?>thumb.jpg" border="0" style="border: 1px solid #35830C" width="113" height="75"></a></font></div> </td> <td valign="top"><div align="left"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><a href="../product.php?ID=<?php echo $row->id; ?>"><?php echo $row->name; ?><br /> </a>Product code: <?php echo $row->id; ?></font><strong><br /> <br /> <br /> £<?php echo $row->price; ?></strong></div></td> <?php } ?> </tr> </table> <br /> that works great, how can i change this to show only 3 columns, and 4 rows??? Quote Link to comment https://forums.phpfreaks.com/topic/84755-solved-quick-layout-problem/#findComment-432128 Share on other sites More sharing options...
Ken2k7 Posted January 6, 2008 Share Posted January 6, 2008 Change LIMIT in your query to 12. Quote Link to comment https://forums.phpfreaks.com/topic/84755-solved-quick-layout-problem/#findComment-432147 Share on other sites More sharing options...
jacko_162 Posted January 6, 2008 Author Share Posted January 6, 2008 i tried that and it shows 12 but on one row? doesnt make a 2nd row..?! Quote Link to comment https://forums.phpfreaks.com/topic/84755-solved-quick-layout-problem/#findComment-432159 Share on other sites More sharing options...
Ken2k7 Posted January 6, 2008 Share Posted January 6, 2008 I'm so sorry. This was my fault. Forgot one thing. Thanks for letting me know. Please try: <table width="100%" height="75" border="0" cellspacing="1" cellpadding="3"><tr> <?php // Query to pull information from the "products" Database $result = mysql_query("select * from $table1 order by id DESC LIMIT 0 , 8"); /* edited below: added 2 lines */ $row_number = 4; $counter = 0; while ($row = mysql_fetch_object($result)) { if ($counter%$row_number==0&&$counter!=0) echo "</tr><tr>"; ?> <td width="113" height="78" valign="top"> <div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><a href="../product.php?ID=<?php echo $row->id; ?>"><img src="../images/products/<?php echo $row->id; ?>thumb.jpg" border="0" style="border: 1px solid #35830C" width="113" height="75"></a></font></div> </td> <td valign="top"><div align="left"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><a href="../product.php?ID=<?php echo $row->id; ?>"><?php echo $row->name; ?><br /> </a>Product code: <?php echo $row->id; ?></font><strong><br /> <br /> <br /> £<?php echo $row->price; ?></strong></div></td> <?php $counter++; } ?> </tr> </table> <br /> Quote Link to comment https://forums.phpfreaks.com/topic/84755-solved-quick-layout-problem/#findComment-432185 Share on other sites More sharing options...
jacko_162 Posted January 6, 2008 Author Share Posted January 6, 2008 Smashing. Thank you so much, i can rest easy now. Quote Link to comment https://forums.phpfreaks.com/topic/84755-solved-quick-layout-problem/#findComment-432194 Share on other sites More sharing options...
redarrow Posted January 6, 2008 Share Posted January 6, 2008 what was not there before was it the increment of counter <?php $counter++; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84755-solved-quick-layout-problem/#findComment-432201 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.