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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.