• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Generating a Dynamic Table

cantbprince

Senior member
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.
 
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>
 
... 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.
 
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.
 
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 😛 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 😕 ) 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.
 
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 (<% ... %>).
 
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.
 
Back
Top