Click to See Complete Forum and Search --> : Asp in tables and splitting the results into multiple pages
bahama llama
03-08-2003, 11:59 PM
This is a follow up to a previous post on image link creation with ASP.
I figured out the code I need for the dynamic image link page creation but now I have several other issues to deal with.
First I would naturally like to place the images in a table. I could just place Response.Write for the table tags and use the table data tags for each image, but what I would like to do is place five images in a top row and five in a bottom row. I do not know how to split the results between the rows. I would also like to be able to limit the first page to 10 images and then provide a link the next ten and so on.
Here is the code I am using, it's included in a SSI for each page so that is why I need it generic so that it will work for multiple dirctories(not a set path in code, rather it finds it for me). All directories will have the same structure, Default.asp, thumbs folder(with thumbs numerically numbered), pic folder(with pics numerically numbered). Here's what I got:
<%
Dim objFSO, objFolder, Counter
path = Server.MapPath("thumbs")
Set objFSO=Server.CreateObject("Scripting.FileSystemObject")
Set objFolder=objFSO.GetFolder(path)
Counter = 0
For Each objFile In objFolder.Files
Counter = Counter + 1
Next
Set objFolder = Nothing
Set objFile = Nothing
Set objFSO = Nothing
dim i
for i=1 to Counter
response.write("<A HREF=pics/"& i &".jpg target=pic ><IMG SRC=thumbs/"& i &".jpg></A>")
next
%>
Thanks in advance guys, I appreciate it. If you can point me to website or tutorial that will help me with this, that would be cool too. Don.l:confused: :t :D
Spardan
03-09-2003, 12:54 PM
For active server help I usually use these guys :
www.asp-help.com (http://www.asp-help.com)
they're pretty comprehensive:t
DocEvi1
03-09-2003, 01:14 PM
www.asp101.com I find useful
The way to create tables is quite easy:
Snipet of your code:
----------------------
response.write("<tr><td with="100%">")
dim i
for i=1 to Counter
if i-1 Mod 5=0 then response.write("</td></tr><tr><td width=100%>")
response.write("<A HREF=pics/"& i &".jpg target=pic ><IMG SRC=thumbs/"& i &".jpg></A>")
next
response.write("</td></tr>
-----------------------------
the Mod formula takes i, divides by 5 and then returns the remainder. Why i-1? Well you need to consider that if i = 5, the new line will be written hence 4 images per line.
On the new pages front, thats a little more involved. What you need to do is create links to your asp page sending variables with it, i.e. the number i to start at:
filename.asp?i=11
then instead of for i=1 to Counter, you get for i=(FROM URL) to Counter.
Stefan
bahama llama
03-09-2003, 07:12 PM
Thanks a lot guys for your help, I'll be trying it either tonight or tomorrow and I'll let you know how it turns out. The code looks good so it go well, I appreciate it. Don.:D :t
kpm547
03-11-2003, 05:14 PM
This is what I would do to put the links into two rows of five and limit the pages to 10 pics
<%
Dim iCount, iPageCount, j, k, iMaxPictures
'determine how many pictures there are
iMaxPictures = 32
iPageCount = Request("pagecount")
If Not VarType(iPageCount) = 2 Or iPageCount > 0 Then
iPageCount = 1
End If
Response.Write("<TABLE>")
iCount = iPageCount*10 - 10
For j = 1 to 2
Response.Write("<TR>")
For k = iCount To iCount + 10
Response.Write("<TD><A HREF='pics/"& iCount &".jpg' target=pic ><IMG SRC='thumbs/"& iCount &".jpg'></A>")
Next
Response.Write("</TR>")
Next
Response.Write("</TABLE>")
If iPageCount - 1 > 1 Then
Response.Write("<A HREF='thispagename.asp?pagecount=" & iPageCount - 1" & "'>Previous</A>")
End If
If iPageCount + 1 < Cint(iMaxPictures/10) Then
Response.Write("<A HREF='thispagename.asp?pagecount=" & iPageCount + 1" & "'>Next</A>")
End If
%>
This should work. I haven't tested it yet. There may be a problem with the "next" link. If there is, you would have to make sure to round up the iMaxPictures/10 to a whole number.
bahama llama
03-11-2003, 10:12 PM
Thanks for the help Doc. But it's returning to me in one large 10 pic cell. Any Ideas? Don.:confused:
DocEvi1
03-12-2003, 01:01 PM
I'm nowhere near a PC capable of runing ASP script at mo so can't test, try putting brackets round i-1 tho.
I'll hava a play when I can run ASP files - probably at Uni tommorow (I uninstalled IIS from my XP machine because I wasn't using it all that much anyhow).
Stefan
bahama llama
03-16-2003, 10:35 PM
Any help? I was wondering if a two dimensional array would work? If so how would I go about putting my code into this? I still have one large cell, doc, I am going to try and fool around with the code but I'm kinda strapped for time. Thanks for the help guys, Don.:D
DocEvi1
03-17-2003, 06:26 AM
oops sorry. I've got **** loads of coursework on at the minute and completely forgot. sorry.
The best I can do is direct you to the attached file. It's in spanish so I couldn't read it all that well but I understood it eventually and modified it for my own uses. It's a .zip file but Sysopt won't accept it. right Click, save as. Rename to thumb.zip.
Pretty much garunteed to be virus free (I updated my checked yesterday plus do so often).
Stefan
bahama llama
03-17-2003, 10:17 PM
Thanks for the reply doc, I can understand that, I'm in college, working full time, married, and have just had a new baby Boy!(well my wife has anyways). I appreciate your help and I'll let you know how it turns out. Don.:D
bahama llama
03-21-2003, 11:57 PM
Hey Doc, I took a look at the code and I'm completly lost. Any help with it ia appreciated. Don.
bahama llama
03-30-2003, 12:34 AM
Hey Doc,
I finally figured out your code! (remember I'm new at ASP).
I had to make a few changes, most notably I changed i-1 mod 5 to (i-1) mod 5 and this corrected the display of one long row.
Here's what I got:
<%
Dim objFSO, objFolder, Counter
path = Server.MapPath("thumbs")
Set objFSO=Server.CreateObject("Scripting.FileSystemObject")
Set objFolder=objFSO.GetFolder(path)
Counter = 0
For Each objFile In objFolder.Files
Counter = Counter + 1
Next
Set objFolder = Nothing
Set objFile = Nothing
Set objFSO = Nothing
response.write("<table>")
response.write("<tr><td>")
dim i
for i=1 to Counter
if (i-1) Mod 5 = 0 then response.write("</td></tr><tr><td>")
response.write("<A HREF=pics/"& i &".jpg target=pic ><IMG SRC=thumbs/"& i &".jpg></A>")
next
response.write("</td></tr>")
%>
My next step will be to limit it too ten images per page with links at the bottom to go forward and back. Any help with this would be appreciated, I will be trying to incorporate the help on this that is already given.
Thanks again everyone! Don:D
DocEvi1
03-30-2003, 07:25 AM
Originally posted by DocEvi1
try putting brackets round i-1 tho.
lol. Thats cool, congrats. Now what I would do is:
1) change i to read from the url not start from 1 each time (remember to have a setting for default i.e. an if statement if the url doesn't have a parameter)
2) change the links to pageName.asp?i=x where x is your starting number
3) change for your loop to for i to (i+10)
to read from the URL use: Request.ServerVariables("Query_String")
It might also be wise to have some sort of validation on i so that the user cannot access the page after the last...
Stefan
SysOpt.com
Copyright Internet.com Inc. All Rights Reserved.