Results 1 to 5 of 5
  1. #1
    Full Member dak142's Avatar
    Join Date
    January 18th, 2005
    I am looking to display 16 thumbnails, 4 wide, 4 in length. How do I set up my echo statement to accomplish this? I have been trying to use 4 seperate PHP statements in the top 4 cells that display 4 thumbnails vertically.

    However, I never get the desired result, seems instead of running 4 x 4, they somehow all go inline, 16 long. Anyone have any advice? It would be much appreciated!


  2. #2
    ABW Ambassador Snib's Avatar
    Join Date
    January 18th, 2005
    This is really simple, just loop through all your thumbnails and links. It helps to keep them in an array. Then just append a </tr><tr> every 4 iterations. What I do is maintain a loop control variable that will increment by one each iteration. Just do something like this:

    if($number % $columns == 0) { echo "</tr><tr>"; }

    Where $columns is a variable containing the number 4. The % means mod which returns the remainder of $number divided by $columns. When it equals 0, that means the number is divisible by 4 (in our case). Here all you need to do is modify $columns to indicate how many columns you'll have. You can go from 2 to any number you wish, but 4 is about the max, maybe 6 if you squeeze them in.

    - Scott
    Hatred stirs up strife, But love covers all transgressions.

  3. #3
    Full Member dak142's Avatar
    Join Date
    January 18th, 2005
    Ok, so sounds to me like I can accomplish this with just one PHP sniplet rather than the 4 I have been trying to use. I have been playing with this but my images still appear vertically rather than horizontially.

    How is your table aranged before the PHP gets parsed? I am thinking this may be my problem? Do you insert your code into a table, or does the code create the table structure for you?

  4. #4
    Full Member
    Join Date
    January 18th, 2005
    I don't have the exact code in front of me but it goes something like this. (I'm not even sure if the following is php or asp or a mix of both....but the logic is the same) You place the TABLE start and closing tags outside of the loop. You basically just spit out <TD>$image</TD> until the desired column numbers equal the number of <TD>'s in which case you close the row and open another.

    Print "<table><tr>";
    for each $image in array
    print "<td>$image</td>"
    if($number % $columns == 0) { print "</tr><tr>"; }
    Print "</tr></table>";

  5. #5
    Full Member dak142's Avatar
    Join Date
    January 18th, 2005
    Got it! Worked very well after a little tweaking for my own use! Thank you all!

  6. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. PHP question - include(file.php) with variables
    By teezone in forum Programming / Datafeeds / Tools
    Replies: 8
    Last Post: September 4th, 2009, 04:54 PM
  2. Using tables with contain statement
    By aprillougheed in forum WebMerge (
    Replies: 7
    Last Post: June 27th, 2004, 10:01 AM
  3. Yet again.. tables and webmerge.
    By >( ^.^)< Kirby in forum WebMerge (
    Replies: 3
    Last Post: May 3rd, 2004, 12:15 PM
  4. Need Help With Tables & IE
    By sweat in forum Programming / Datafeeds / Tools
    Replies: 6
    Last Post: July 10th, 2003, 12:29 PM

Posting Permissions

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