Generating a Dynamic Table

cantbprince

Senior member
Jun 4, 2005
290
0
0
What i want to do is create a table based on the number of elements i may have. Given a max Element per row displays as many rows as needed.

Ex. Reading 13 images from directory and 5 elements per row. The application should output.
* * * * *
* * * * *
* * *
Given 6 images it should display
* * * * *
*

Thanks.
 

Hersh

Senior member
Oct 14, 1999
331
0
0
I have zero experience with JSP but the algorithm should be simple.

Set a variable to be equal to the number of images divided by the indicated row number (we'll denote this variable as TR), so in your case TR = 13 / 5 = 2.6. Try finding a function that would basically round the number up or simply do 13 % 5 and see if the result is greater than 0 then TR++ assuming TR is simply an integer variable.

Pseudo-pseudo-code just so you'll get the idea:
<table>
loop1: from 0 to TR - 1 loop spit out a <TR> tag
loop2 nested: from 0 to (number of elements per row) - 1 loop spit out a <TD> tag then the image then the </TD> tag
end loop2
spit out </TR> tag
end loop1
</table>
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
... deleted stuff ...
Edit: my bad, thought this was a programming assignment...

This is pretty easy with a single loop and a counter. Loop through all the elements and check the counter each time. If it hits 5, reset it and start a new line.
 

cantbprince

Senior member
Jun 4, 2005
290
0
0
Originally posted by: kamper
... deleted stuff ...
Edit: my bad, thought this was a programming assignment...

This is pretty easy with a single loop and a counter. Loop through all the elements and check the counter each time. If it hits 5, reset it and start a new line.

Lol no its not a programming assignment at all.... my assignments were much harder than this lol. REally simple but my brain was broken.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Originally posted by: cantbprince
Originally posted by: kamper
... deleted stuff ...
Edit: my bad, thought this was a programming assignment...

This is pretty easy with a single loop and a counter. Loop through all the elements and check the counter each time. If it hits 5, reset it and start a new line.

Lol no its not a programming assignment at all.... my assignments were much harder than this lol. REally simple but my brain was broken.
Stuff like drawing the stars looked an awful lot like the first few assignments I had for my intro to programming java course :p I was only asking for clarification (no rants or anything) but then I saw your other thread about jsp (which I'd already replied to :confused: ) and realized that you had just written the above as an example. Btw, it is quite possible to do without specifying a wrap length and just having the browser decide where to cut it based on the viewing area.
 

itachi

Senior member
Aug 17, 2004
390
0
0
this is one of those things that should be done client-side.. it can be done a lot more easily and effectively through javascript.

if u want to do it using jsp, just insert the logic into a scriptlet (<% ... %>).
 

Argo

Lifer
Apr 8, 2000
10,045
0
0
The code below hasn't been tested for bugs but it should give you a general idea. Make sure you import all the taglbis used.