Omzy Posted October 7, 2009 Share Posted October 7, 2009 What I'm trying to acheive is something very basic - a grid of products in rows of 5 - I could do this with tables but I'm trying to use semantic design concepts so I'm using UL/LI tags. I've got a CSS property of { li: border-top: 1px solid black }, so this basically displays a border at the top of the LI so that each row of 5 products is seperated by a border. So far so good, however the problem is when the total number of products is not a multiple of 5 then the row border is incomplete. Here's how I'm displaying the products (from a database): for($i=0; $i<$numrows; $i++) { echo "<li><a href=\".$products[$i]).".jpg\" \"><img src=\"images/products/thumbs/".$products[$i]).".jpg\" alt=\"\" /></a></li>"; } I think basically what I need is to display extra (blank) LI tags when the total number of products is not a multiple of 5. I tried putting in a conditional IF statement within the FOR loop and then changing $i<$numrows to $i<5 || $i <10 but this messes up the display. Anyone got any more ideas? Quote Link to comment Share on other sites More sharing options...
Omzy Posted October 7, 2009 Author Share Posted October 7, 2009 I fixed it myself: if($numrows<=5) { $total=5; } elseif($numrows<=10) { $total=10; } for($i=0; $i<$total; $i++) { if($i<$numrows) { //echo the product } else { //echo the blank LI } } Quote Link to comment Share on other sites More sharing options...
Omzy Posted October 7, 2009 Author Share Posted October 7, 2009 Does anyone know how I can do this more elegantly, i.e. without having to hardcode the values in several IF conditions, and make it work out what the value of $total should be based on how many products there are? So if there are 7 products then it needs to know that the required multiple of 5 is 10. Quote Link to comment 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.