Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically Creating a table that displays images 2

Status
Not open for further replies.

fchan

MIS
Jul 2, 2001
47
US
I want to dynamically create a table to display thumbnail images. The table should only have four columns, but can have as many rows as needed to display all the images. I am pulling the images from my web server using the FileSystemObject object and I am inserting the file name into the image tag.

My challenge is how to only limit the table to four columns while still looping through all the image files in the folder. Here is my code:
****************
<table width=&quot;100%&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;1&quot;>
<%
dim objFSO, strPath, objFiles, objFolder
strPath = &quot;c:\inetpub\set objFSO = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
if objFSO.FolderExists(strPath) then
'Response.Write &quot;yes&quot;
set objFolder = objFSO.GetFolder(strPath)
Response.Write &quot;<tr>&quot;
for each objFiles in objFolder.files
if LCase(Right(objFiles.name,4)) = &quot;.gif&quot; then
Response.Write &quot;<td>&nbsp;<img src='&quot; & objFiles.name & &quot;'>&quot; & i & &quot;</td>&quot;
end if
next
Response.Write &quot;</tr>&quot;
else
Response.Write &quot;no&quot;
end if
%>
</table>
*************************************

Any ideas or am I attempting something that is not worth the effort? I'm attempting this mainly so that I can write a subroutine for later use so I won't have to manually code the images in my web page.

Thanks
 
The only problem I see is you don't have a way for them to be spread across multiple rows, that appears to put them all on the same row.
How about adding this:
Code:
<table width=&quot;100%&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;1&quot;>
<%
dim objFSO, strPath, objFiles, objFolder
strPath = &quot;c:\inetpub\[URL unfurl="true"]wwwroot\felix\TestImages&quot;[/URL]
set objFSO = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)

Dim rowCounter

if objFSO.FolderExists(strPath) then
    'Response.Write &quot;yes&quot;
    set objFolder = objFSO.GetFolder(strPath)
    for each objFiles in objFolder.files
        If rowCounter mod 4 = 0 Then Response.Write &quot;<tr>&quot;  'only start row before 1st of 4 elements
        if LCase(Right(objFiles.name,4)) = &quot;.gif&quot; then
            Response.Write &quot;<td> <img src='&quot; & objFiles.name & &quot;'>&quot; & i & &quot;</td>&quot;    
        end if
        If rowCounter mod 4 = 3 Then Response.Write &quot;</tr>&quot; 'only end row on 4th element
        rowCounter = rowCounter + 1
    next
If rowCounter mod 4 < 3 Then Response.Write &quot;</tr>&quot;  'take care oif last row if it wasn't full
else
    Response.Write &quot;no&quot;
end if
%>
</table>

You may also want to specify a width on the images or columns to keep your table uniform. I would assume you don't need to check for anything but .gif since you will be placing the images in the directory your self.

Another option here is to create a small database or text file that lists the image paths, than you could just loop through either the table or file creating image tags.

-Tarwn &quot;If you eat a live toad first thing in the morning, nothing worse will happen all day long.&quot; - California saying
&quot;To you or the toad&quot; - Niven's restatement of California saying
&quot;-well most of the time anyway...&quot; - programmers caveat to Niven's restatement of California saying
(The Wiz Biz - Ri
 
I don't quite understand.. You're code seems to be pretty much there, what do you need help on?

If you're just stuck on how to limit the table to 4 cells wide then just create a 'count' variable which adds one each file, and when it equals '4' just end the </TR>, then reset the variable.

Nick (Software Developer)


nick@retrographics.fsnet.co.uk
nick.price@myenable.com
 
Thanks for the help. I think I figured it out. =)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top