Jump to content

Displaying products : formatting issue


Omzy

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/176832-displaying-products-formatting-issue/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.