j.smith1981 Posted February 3, 2011 Share Posted February 3, 2011 This is really just a general question that I am quite interested in developing. Say I had a list of products with the following attributes right? productid = 1 (smallint(3)) productname = "Product 1" (varchar, to reduce space) price = 25.99 (double, more precise for currency?) --please correct me if I am wrong But say this spanned out to say 6 products per line on the user viewing the page. With then 5 rows down. product1 | product2 | product3 | product4 | product5 | product6 product7 | product8 | product9 | product10 | product11 | product12 And so on until all products have been displayed right? How would I do this theoretically in PHP to limit that no of results per row? Always been confused on how this is doable, want to eventually construct my own ecommerce, really get into the nuts and bolts of it. Thanks and I appreciate any reples, Jeremy. Quote Link to comment https://forums.phpfreaks.com/topic/226558-how-the-theory-would-work-to-display-a-set-list-of-products-using-columns/ Share on other sites More sharing options...
DeadxBeat Posted February 3, 2011 Share Posted February 3, 2011 Are you displaying the results in a table? If you are then you could just use a counter in your loop that retrieves the data. $maxrows = 3; // max number of rows per column $count = 0; // counter for loop echo ' '; // start table echo ' '; // start first column in table loop { // whatever kind of loop you decide to use if($count == $maxrows){ // if the $counter variable equals max rows per column var the $count = 0; // set $count back to 0 echo ' '; // close your column, start a new one } $count++; // increment $count by 1 echo ' '; //new row } // close loop Quote Link to comment https://forums.phpfreaks.com/topic/226558-how-the-theory-would-work-to-display-a-set-list-of-products-using-columns/#findComment-1169486 Share on other sites More sharing options...
j.smith1981 Posted February 11, 2011 Author Share Posted February 11, 2011 Oh thank you so much for that! I just couldnt work out the logic myself but that makes perfect sense. Jez. Quote Link to comment https://forums.phpfreaks.com/topic/226558-how-the-theory-would-work-to-display-a-set-list-of-products-using-columns/#findComment-1172671 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.