Rows and cells and rows and cells...

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

Why isn't this working?? Specifically, why are no rows and cells being printed? All I get is the stuff before and after this segment of code.

code:

foreach $i (@images) 
     {
     if ($i == 0) 
        {
        print "<tr>\n"; 
        }
     elsif ($i > 0) 
        {
        print "<td>something here</td>\n";
        }
     else 
        {
        print "<td> </td>\n";
        }
     $i+=1;
     if ($i == 5) 
        {
        print "</tr>\n";
        $i = 0;
        }
     }

[/code]

Any suggestions would be welcomed!

------------------
Zero Cattle
Suzanne
Tables DeMystified 

They have: 850 posts

Joined: Jul 1999

Make sure you have
print "Content-type:text/html\n\n";

------------------
L34RN |-|0\/\/ T0 5P34K L33T JU5T L1K3 4N 40L |-|4X0R
http://www.wiredstart.com : The Technology Start Page

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

Yes, I do have that...

It is printing the other bits --

code:

print "<table border=0 cellpadding=0 cellspacing=0 bgcolor=\#ffffcc width=450>";
[/code]

Prints and so does:

code:
print "</table>\n";
[/code]

Which are the lines above and below the previous snip...

I am thinking there must be something wrong with the list (from my last post about how to get a multi-dimensional list read into the code), but I am at a loss.

I am getting no errors when testing, just nothing in between the table tags.

Ack!

  Suzanne

------------------
Zero Cattle
Suzanne
Tables DeMystified 

They have: 161 posts

Joined: Dec 1999

Your problem is that

code:

for $i (@images) { ... }
[/code]

Loops over the ACTUAL ELEMENTS of the array, as opposed to their indices.  I'm not too sure what your code is supposed to do, because of that misunderstanding.

Here's a possible solution:

code:
for $img (@images) {
  print "<tr>\n" if !$c++;
  print "<td>$img</td>\n";
  $c = 0, print "<tr>\n" if $c == 4;
}
[/code]

------------------
-- 
MIDN 4/C PINYAN, NROTCURPI, US Naval Reserve 

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.