MizzBia

msg:3792409 | 11:27 am on Nov 23, 2008 (gmt 0) |
What I actually meant is... How to display multiple results/data per row. Lets say I am displaying images... Instead of displaying them one after another, is there a way I can display them 3 per row? Sorry about my first post, I'm exhausted and it probably didn't make much sense.
|
phranque

msg:3792462 | 2:20 pm on Nov 23, 2008 (gmt 0) |
if you were displaying 3 records per row: <table> <tr> <td>$NAME</td> <td>$EMAIL</td> <td>$SITE</td> <td>$NAME</td> <td>$EMAIL</td> <td>$SITE</td> <td>$NAME</td> <td>$EMAIL</td> <td>$SITE</td> </tr> </table> assuming you are generating the html content in perl, your trick is to have the loop put out the <tr> tag before the first and every third record and then put out the </tr> tag after every third record. you probably also need to handle the blank cells at the end of the last row if the number of records is not evenly divisible by 3. hint: modulus operator [perldoc.perl.org]
|
rocknbil

msg:3792504 | 4:57 pm on Nov 23, 2008 (gmt 0) |
| Lets say I am displaying images... Instead of displaying them one after another, is there a way I can display them 3 per row? |
| This is a simple solution laying the cells in horizontally. If you want to lay them in vertically, you'll have to use phranque's approach and do some precursory math on the length of the list. # make a list of all images for the page, # store them in an array. In this case, I'm using a hash # that contains filename=>caption %images = &get_images; # Num columns $cols = 3; # A counter to keep track $counter = 0; # Start output: $out = '<html><body><table>'; foreach $v (sort keys %images) { if ($count == 0) { $out .= '<tr>'; } $out .= qq(<td><img src="$v"><br>$images{$v}</td>); # When $count gets to $col (3), reset it. # this starts a new row on the next loop. $count++; if ($count >= $col) { $out .= '</tr>'; $count=0; } } }
# The images are done, now let's address the last row. # If $col == 0 or 3, this will do nothing. BUT if # it's less than 3, create empty cells to even out # the columns of the last row.
if (($count > 0) && ($count < $col)) { for $i ($count..$col) { $out .= '<td> </td>'; } $out .= '</tr>'; } $out .= '</table></body></html>';
print "content-type: text/html\n\n"; print $out; Typed on a whim, may contain syntax errors, but this aproach works. [edited by: phranque at 10:42 pm (utc) on Nov. 23, 2008] [edit reason] disabled smileys ;) [/edit]
|
MizzBia

msg:3792582 | 8:22 pm on Nov 23, 2008 (gmt 0) |
Thank you both! I'll go through your tips and see if I can figure this out.
|
rocknbil

msg:3793930 | 3:32 pm on Nov 25, 2008 (gmt 0) |
| [edit reason] disabled smileys ;) [/edit] |
| ACK! I used the checkbox too!
|
phranque

msg:3794202 | 9:54 pm on Nov 25, 2008 (gmt 0) |
if you edited afterwards you have to recheck the checkbox.
|
|