SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2005
    Location
    fulham
    Posts
    137
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question what the best way to create columns of products

    Hi

    I have a layout issue where I wont to line up my products of different sizes in two columns like in example 1 not the traditional way in example 2.



    Any pointers / advise would be much appreciated.
    Please note I'm a relative novice with PHP & MySQL.
    Cheers

    Coup

  2. #2
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Are you using table layout, or CSS layout ?
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  3. #3
    SitePoint Evangelist ldivinag's Avatar
    Join Date
    Jan 2005
    Location
    N37 33* W122 3*
    Posts
    414
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    simple actually.

    divide number of products by the number of columns you want. CEIL the result.

    in this case 8 products and 2 colums. you get 4 rows.

    so now you know how many rows are needed, you just need to calculate which products go in each cell.

    in this case, column 1 of row 1 will be the first product. but column 2 of row 1 will be prod 5.


    so now, for some psuedo code:

    PHP Code:
    $number_of_rows CEIL($total_number_of_products $number_of_columns);
    insert_code_to_draw_start_of_table_HTML_code;
    for (
    $loop==1$loop<=$number_of_rows$loop++)
    {
      
    insert_code_to_draw_start_of_table_ROW_HTML_code;
      for (
    $loop2==0$loop2<=$number_of_columns$loop2++)
      {
        
    populate_column ($loop+($number_of_rows*$loop2));
      }
      
    insert_code_to_draw_end_of_table__ROW_HTML_code;
    }
    insert_code_to_draw_end_of_table_HTML_code
    should work for any number of columns. only thing to check is for the last row.

    lets say, like your example, but you only have 7 products. row 4, column 2 would be empty. so just check for that...

    edit: forget what i said about the MODULUS operator. i was thinking of something else... doh...

    edit#2, CEIL, not FLOOR
    Last edited by ldivinag; Aug 13, 2005 at 02:59.
    leo d.

  4. #4
    SitePoint Zealot
    Join Date
    Jan 2005
    Location
    fulham
    Posts
    137
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mandes
    Are you using table layout, or CSS layout ?
    I'm using CSS but can use table or a combination of both if needed.
    Cheers

    Coup

  5. #5
    SitePoint Zealot
    Join Date
    Jan 2005
    Location
    fulham
    Posts
    137
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ldivinag
    simple actually.

    divide number of products by the number of columns you want. CEIL the result.
    This works but it doesn’t solve my problem 100%

    What if the first 4 products are very long and the last 4 products are very small. Ideally you should have 3 products on one side and 5 on the other.

    Is this something you will be able to calculate in PHP or is it a problem for the DMTML boys.
    Last edited by coup; Aug 13, 2005 at 07:32.
    Cheers

    Coup

  6. #6
    SitePoint Zealot
    Join Date
    Mar 2003
    Location
    Morges Switzerland
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by coup
    What if the first 4 products are very long and the last 4 products are very small. Ideally you should have 3 products on one side and 5 on the other.
    If you want the columns of equal size then you need to know the length of each item. For images you can get the height, for text it is more difficult, try to count the number of <br /> and the number of characters. A fixed format will be very helpful.

    Then the length of the products must be analyzed to make two equal length columns.

    wimb
    Last edited by wimb; Aug 15, 2005 at 11:26.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •