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!

Images per page 12 - 16 - 32 - 64

Status
Not open for further replies.

enzobanzai

Technical User
Jun 24, 2004
16
AU
Hi

I am trying to get a feature to work on a clients website.

I am building a image library in ASP VB Script and I want the user to be
able to select the amount of images they view on the page.

eg. Images per page 12 - 16 - 32 - 64

So selecting 12 for example would only show 12 records.

I am using the Horizontal Looper extension to display my images in 4
columns.

Have anyone ever done this before or know of how to do it?

Any help will be greatly appreciated.

Here are some examples that I have seen:


Thanks and regards
David Forshaw
 
i'm assuming you are using a db to grab the image names and you are loop through the records to show the images

and you say you are also using a horizontal looper

basic i would do something like this, have the drop menu when someone picks the amount of images to go to the querystring when they hit a button

then your loop would look something like this

Code:
numberofimages=clng(request.querystring("querystringname"))

for rows=0 to (numberofimages/4)-1 
'amount of rows to loop 12/4 =3 rows, 
'12 being the queryystring
'4 the amount of cols
'3 being the amount of rows

response.write "<tr>"

  for cols=1 to 4 
  'this is your horizontal looper of 4 columns

... the rest of your code
 
enz,
don't forget to put in next statements for the for loops

bsl
 
Are the images, or the URLs for the images, stored in a database?
 
Yes they are.

They are stored in a Access database????

Dave
 
the solution i gave should do the trick but post your code if your not sure where to put
 
Or is the question how to retrieve only the correct rows from the db? I'm not clear on this.
 
Hi Steven

Here is my code (as I am working on right now)

To tell you the truth I am not sute what you mean but I really appreciate your help.

------------------------------------------------------------
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="../../Connections/connKirkland.asp" -->
<%
Dim rsImageList__MMColParam
rsImageList__MMColParam = "1"
If (Request.QueryString("destID") <> "") Then
rsImageList__MMColParam = Request.QueryString("destID")
End If
%>
<%
Dim rsImageList
Dim rsImageList_numRows

Set rsImageList = Server.CreateObject("ADODB.Recordset")
rsImageList.ActiveConnection = MM_connKirkland_STRING
rsImageList.Source = "SELECT * FROM qry_imageList WHERE intDestID = " + Replace(rsImageList__MMColParam, "'", "''") + " ORDER BY intImageSort ASC"
rsImageList.CursorType = 0
rsImageList.CursorLocation = 2
rsImageList.LockType = 1
rsImageList.Open()

rsImageList_numRows = 0
%>
<%
Dim rsSearchDest
Dim rsSearchDest_numRows

Set rsSearchDest = Server.CreateObject("ADODB.Recordset")
rsSearchDest.ActiveConnection = MM_connKirkland_STRING
rsSearchDest.Source = "SELECT intDestID, txtDestName FROM tbl_Destination ORDER BY txtDestName ASC"
rsSearchDest.CursorType = 0
rsSearchDest.CursorLocation = 2
rsSearchDest.LockType = 1
rsSearchDest.Open()

rsSearchDest_numRows = 0
%>
<%
Dim HLooper1__numRows
HLooper1__numRows = 12
Dim HLooper1__index
HLooper1__index = 0
rsImageList_numRows = rsImageList_numRows + HLooper1__numRows
%>
<%
' *** Recordset Stats, Move To Record, and Go To Record: declare stats variables

Dim rsImageList_total
Dim rsImageList_first
Dim rsImageList_last

' set the record count
rsImageList_total = rsImageList.RecordCount

' set the number of rows displayed on this page
If (rsImageList_numRows < 0) Then
rsImageList_numRows = rsImageList_total
Elseif (rsImageList_numRows = 0) Then
rsImageList_numRows = 1
End If

' set the first and last displayed record
rsImageList_first = 1
rsImageList_last = rsImageList_first + rsImageList_numRows - 1

' if we have the correct record count, check the other stats
If (rsImageList_total <> -1) Then
If (rsImageList_first > rsImageList_total) Then
rsImageList_first = rsImageList_total
End If
If (rsImageList_last > rsImageList_total) Then
rsImageList_last = rsImageList_total
End If
If (rsImageList_numRows > rsImageList_total) Then
rsImageList_numRows = rsImageList_total
End If
End If
%>

<%
' *** Recordset Stats: if we don't know the record count, manually count them

If (rsImageList_total = -1) Then

' count the total records by iterating through the recordset
rsImageList_total=0
While (Not rsImageList.EOF)
rsImageList_total = rsImageList_total + 1
rsImageList.MoveNext
Wend

' reset the cursor to the beginning
If (rsImageList.CursorType > 0) Then
rsImageList.MoveFirst
Else
rsImageList.Requery
End If

' set the number of rows displayed on this page
If (rsImageList_numRows < 0 Or rsImageList_numRows > rsImageList_total) Then
rsImageList_numRows = rsImageList_total
End If

' set the first and last displayed record
rsImageList_first = 1
rsImageList_last = rsImageList_first + rsImageList_numRows - 1

If (rsImageList_first > rsImageList_total) Then
rsImageList_first = rsImageList_total
End If
If (rsImageList_last > rsImageList_total) Then
rsImageList_last = rsImageList_total
End If

End If
%>
<%
Dim MM_paramName
%>
<%
' *** Move To Record and Go To Record: declare variables

Dim MM_rs
Dim MM_rsCount
Dim MM_size
Dim MM_uniqueCol
Dim MM_offset
Dim MM_atTotal
Dim MM_paramIsDefined

Dim MM_param
Dim MM_index

Set MM_rs = rsImageList
MM_rsCount = rsImageList_total
MM_size = rsImageList_numRows
MM_uniqueCol = ""
MM_paramName = ""
MM_offset = 0
MM_atTotal = false
MM_paramIsDefined = false
If (MM_paramName <> "") Then
MM_paramIsDefined = (Request.QueryString(MM_paramName) <> "")
End If
%>
<%
' *** Move To Record: handle 'index' or 'offset' parameter

if (Not MM_paramIsDefined And MM_rsCount <> 0) then

' use index parameter if defined, otherwise use offset parameter
MM_param = Request.QueryString("index")
If (MM_param = "") Then
MM_param = Request.QueryString("offset")
End If
If (MM_param <> "") Then
MM_offset = Int(MM_param)
End If

' if we have a record count, check if we are past the end of the recordset
If (MM_rsCount <> -1) Then
If (MM_offset >= MM_rsCount Or MM_offset = -1) Then ' past end or move last
If ((MM_rsCount Mod MM_size) > 0) Then ' last page not a full repeat region
MM_offset = MM_rsCount - (MM_rsCount Mod MM_size)
Else
MM_offset = MM_rsCount - MM_size
End If
End If
End If

' move the cursor to the selected record
MM_index = 0
While ((Not MM_rs.EOF) And (MM_index < MM_offset Or MM_offset = -1))
MM_rs.MoveNext
MM_index = MM_index + 1
Wend
If (MM_rs.EOF) Then
MM_offset = MM_index ' set MM_offset to the last possible record
End If

End If
%>
<%
' *** Move To Record: if we dont know the record count, check the display range

If (MM_rsCount = -1) Then

' walk to the end of the display range for this page
MM_index = MM_offset
While (Not MM_rs.EOF And (MM_size < 0 Or MM_index < MM_offset + MM_size))
MM_rs.MoveNext
MM_index = MM_index + 1
Wend

' if we walked off the end of the recordset, set MM_rsCount and MM_size
If (MM_rs.EOF) Then
MM_rsCount = MM_index
If (MM_size < 0 Or MM_size > MM_rsCount) Then
MM_size = MM_rsCount
End If
End If

' if we walked off the end, set the offset based on page size
If (MM_rs.EOF And Not MM_paramIsDefined) Then
If (MM_offset > MM_rsCount - MM_size Or MM_offset = -1) Then
If ((MM_rsCount Mod MM_size) > 0) Then
MM_offset = MM_rsCount - (MM_rsCount Mod MM_size)
Else
MM_offset = MM_rsCount - MM_size
End If
End If
End If

' reset the cursor to the beginning
If (MM_rs.CursorType > 0) Then
MM_rs.MoveFirst
Else
MM_rs.Requery
End If

' move the cursor to the selected record
MM_index = 0
While (Not MM_rs.EOF And MM_index < MM_offset)
MM_rs.MoveNext
MM_index = MM_index + 1
Wend
End If
%>
<%
' *** Move To Record: update recordset stats

' set the first and last displayed record
rsImageList_first = MM_offset + 1
rsImageList_last = MM_offset + MM_size

If (MM_rsCount <> -1) Then
If (rsImageList_first > MM_rsCount) Then
rsImageList_first = MM_rsCount
End If
If (rsImageList_last > MM_rsCount) Then
rsImageList_last = MM_rsCount
End If
End If

' set the boolean used by hide region to check if we are on the last record
MM_atTotal = (MM_rsCount <> -1 And MM_offset + MM_size >= MM_rsCount)
%>
<%
' *** Go To Record and Move To Record: create strings for maintaining URL and Form parameters

Dim MM_keepNone
Dim MM_keepURL
Dim MM_keepForm
Dim MM_keepBoth

Dim MM_removeList
Dim MM_item
Dim MM_nextItem

' create the list of parameters which should not be maintained
MM_removeList = "&index="
If (MM_paramName <> "") Then
MM_removeList = MM_removeList & "&" & MM_paramName & "="
End If

MM_keepURL=""
MM_keepForm=""
MM_keepBoth=""
MM_keepNone=""

' add the URL parameters to the MM_keepURL string
For Each MM_item In Request.QueryString
MM_nextItem = "&" & MM_item & "="
If (InStr(1,MM_removeList,MM_nextItem,1) = 0) Then
MM_keepURL = MM_keepURL & MM_nextItem & Server.URLencode(Request.QueryString(MM_item))
End If
Next

' add the Form variables to the MM_keepForm string
For Each MM_item In Request.Form
MM_nextItem = "&" & MM_item & "="
If (InStr(1,MM_removeList,MM_nextItem,1) = 0) Then
MM_keepForm = MM_keepForm & MM_nextItem & Server.URLencode(Request.Form(MM_item))
End If
Next

' create the Form + URL string and remove the intial '&' from each of the strings
MM_keepBoth = MM_keepURL & MM_keepForm
If (MM_keepBoth <> "") Then
MM_keepBoth = Right(MM_keepBoth, Len(MM_keepBoth) - 1)
End If
If (MM_keepURL <> "") Then
MM_keepURL = Right(MM_keepURL, Len(MM_keepURL) - 1)
End If
If (MM_keepForm <> "") Then
MM_keepForm = Right(MM_keepForm, Len(MM_keepForm) - 1)
End If

' a utility function used for adding additional parameters to these strings
Function MM_joinChar(firstItem)
If (firstItem <> "") Then
MM_joinChar = "&"
Else
MM_joinChar = ""
End If
End Function
%>
<%
' *** Move To Record: set the strings for the first, last, next, and previous links

Dim MM_keepMove
Dim MM_moveParam
Dim MM_moveFirst
Dim MM_moveLast
Dim MM_moveNext
Dim MM_movePrev

Dim MM_urlStr
Dim MM_paramList
Dim MM_paramIndex
Dim MM_nextParam

MM_keepMove = MM_keepBoth
MM_moveParam = "index"

' if the page has a repeated region, remove 'offset' from the maintained parameters
If (MM_size > 1) Then
MM_moveParam = "offset"
If (MM_keepMove <> "") Then
MM_paramList = Split(MM_keepMove, "&")
MM_keepMove = ""
For MM_paramIndex = 0 To UBound(MM_paramList)
MM_nextParam = Left(MM_paramList(MM_paramIndex), InStr(MM_paramList(MM_paramIndex),"=") - 1)
If (StrComp(MM_nextParam,MM_moveParam,1) <> 0) Then
MM_keepMove = MM_keepMove & "&" & MM_paramList(MM_paramIndex)
End If
Next
If (MM_keepMove <> "") Then
MM_keepMove = Right(MM_keepMove, Len(MM_keepMove) - 1)
End If
End If
End If

' set the strings for the move to links
If (MM_keepMove <> "") Then
MM_keepMove = Server.HTMLEncode(MM_keepMove) & "&"
End If

MM_urlStr = Request.ServerVariables("URL") & "?" & MM_keepMove & MM_moveParam & "="

MM_moveFirst = MM_urlStr & "0"
MM_moveLast = MM_urlStr & "-1"
MM_moveNext = MM_urlStr & CStr(MM_offset + MM_size)
If (MM_offset - MM_size < 0) Then
MM_movePrev = MM_urlStr & "0"
Else
MM_movePrev = MM_urlStr & CStr(MM_offset - MM_size)
End If
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>
function Thumbnail(tmb_suff,tmb_filename)
Dim tmb_NewFilename, tmb_Path, tmb_PosPath, tmb_PosExt
if not isnull(tmb_filename) then
tmb_PosPath = InStrRev(tmb_filename,"/")
tmb_Path = ""
if tmb_PosPath > 0 then
tmb_Path = mid(tmb_filename,1,tmb_PosPath)
end if
tmb_PosExt = InStrRev(tmb_filename,".")
if tmb_PosExt > 0 then
tmb_NewFilename = tmb_Path & mid(tmb_filename,tmb_PosPath+1,tmb_PosExt-(tmb_PosPath+1)) & tmb_suff & ".jpg"
else
tmb_NewFilename = tmb_Path & mid(tmb_filename,tmb_PosPath+1,len(tmb_filename)-tmb_PosPath) & tmb_suff & ".jpg"
end if
end if
Thumbnail = tmb_NewFilename
end function
</SCRIPT>
<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>
function CI_Preserve(str)
on error resume next
CI_Preserve = Replace(str,Chr(13),"<br>")
End Function
</SCRIPT>
<html xmlns="<head>
<title>List</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="cssStyles/plStyle.css" rel="stylesheet" type="text/css" />
</head>

<body>
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr align="left" valign="top">
<td><strong class="yellow14"><%=(rsImageList.Fields.Item("txtDestName").Value)%></strong><br />
<span class="white11"><%= CI_Preserve((rsImageList.Fields.Item("txtDestDescription").Value)) %></span><br />
<br />
<span class="white12">Displaying images</span> <span class="yellow12"><%=(rsImageList_first)%></span> <span class="white12">to</span> <span class="yellow12"><%=(rsImageList_last)%></span> <span class="white12">of</span> <span class="yellow12"><%=(rsImageList_total)%></span><br />
<br />
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="33%"><span class="white12">Pages</span> <span class="white12">xx</span> </td>
<td width="26%">&nbsp; </td>
<td width="41%" align="right" class="HomePageTD"><span class="white12">Images per page</span> <span class="white12">12 - 16 - 32 - 64 </span></td>
</tr>
</table>
<br />
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<%
startrw = 0
endrw = HLooper1__index
numberColumns = 4
numrows = 3
while((numrows <> 0) AND (Not rsImageList.EOF))
startrw = endrw + 1
endrw = endrw + numberColumns
%>
<tr align="center" valign="top">
<%
While ((startrw <= endrw) AND (Not rsImageList.EOF))
%>
<td align="left">
<table width="150" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="120" colspan="2" align="left" valign="bottom"><img src="images/images/<%= Thumbnail("s",(rsImageList.Fields.Item("txtThumbnail").Value)) %>" /></td>
<td width="10" rowspan="2">&nbsp;</td>
</tr>
<tr>
<td height="30" class="white12"><%=(rsImageList.Fields.Item("txtImageNumber").Value)%></td>
<td height="40"><img src="images/template/but_cart.gif" width="19" height="19" /> <img src="images/template/but_view.gif" width="19" height="19" /></td>
</tr>
</table></td>
<%
startrw = startrw + 1
rsImageList.MoveNext()
Wend
%>
</tr>
<tr align="center" valign="top">
<td align="left">&nbsp; </td>
</tr>
<%
numrows=numrows-1
Wend
%>
</table></td>
<td width="222" bgcolor="#000000"><img src="../images/spacer.gif" width="222" height="10" border="1" /></td>
</tr>
</table>

</body>
</html>
<%
rsImageList.Close()
Set rsImageList = Nothing
%>
<%
rsSearchDest.Close()
Set rsSearchDest = Nothing
%>
 
Hi Steven

Ive got the page displaying the records from the database working perfectly.

What I want though is a feature where the user can select how many records are displayed on the page.

I cant get this to work?

dave
 
try this

replace this line

<span class="white12">12 - 16 - 32 - 64 </span>

with

<span class="white12"><a href="thispage.asp?perpage=12">12</a> - <a href="thispage.asp?perpage=16">16</a> - 32 - 64 </span>
 
then change this

numrows = 3

with this line

numrows = cling(request.querystring("perpage"))/numberColumns

 
also on this new line

<span class="white12"><a href="thispage.asp?perpage=12">12</a> - <a href="thispage.asp?perpage=16">16</a> - 32 - 64 </span>

replace thispage.asp with you page name
 
you really should learn not to use Dreamweaver - you could probably pull this off with 30 lines of code instead of 461
 
also change this line

HLooper1__numRows = 12

to this

HLooper1__numRows = cling(request.querystring("perpage"))
 
Thanks Steven

Ill give it a go.

I hear you about dreamwever but thats the way I was taught (Studies) and now I have been thrown into the deep end.

One day I set about learning code so I can hand code but for now Dreamweavers my best and worst friend.

Cheers
David
 
i use to use - it took about 1 month to get the hang of not using it but believe me, its worth it, saves a lot of time and you have greater possiblities
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top