green'n'white
07-16-2006, 11:41 AM
Hi,
Can anybody help with this coding, it is the image gallery offered up by Buntine, the only thing is,
when more than 9 pictures are in one category it creates a new page with a link at the bottom i.e Page (1,2,3....). When clicking on the link for a particular page the gallery category is requested along with the page id, i.e. gallery_id=3&page=1 but the page returned when 'page=?' is present in the menu bar is always the last page in the category.
The code for the page is;
<!-- #include file="includes/adovbs.inc" -->
<!-- #include file="includes/conn.asp" -->
<%
Dim rs, sql, i
Dim intGallery, intPage
intGallery = Request.QueryString("gallery_id")
intPage = nvl(Request.QueryString("page"), 1)
Public Function getFileName(strFile)
Dim strExt, strAddon
strAddon = "_small"
strExt = Right(strFile, 4)
getFileName = Left(strFile, Len(strFile) - 4) & _
strAddon & strExt
End Function
Public Function getPlural(str, count)
If count > 1 Then
getPlural = str & "s"
Else
getPlural = str
End If
End Function
Set rs = Server.CreateObject("ADODB.RecordSet")
sql = "SELECT g.gallery_id, g.gallery_title, COUNT(i.image_id) AS imgCount FROM galleries g, images i WHERE " & _
"i.gallery_id = g.gallery_id GROUP BY g.gallery_id, g.gallery_title;"
rs.Open(sql), conn, 3
If rs.EOF And rs.BOF Then
dispError("No records returned. Please try again")
End If
%>
<link rel="stylesheet" type="text/css" href="styles/generic.css"></link>
<!--#include virtual="/head.inc" -->
<div align="center" style="margin-top: 20px;">
<form action="<%= Request.ServerVariables("SCRIPT_NAME") %>" method="get">
<table class="gallery" cellspacing="0">
<tr>
<td valign="middle" class="gallery_header_left">Galleries: </td>
<td valign="middle" class="gallery_header_center">
<select name="gallery_id">
<%
rs.MoveFirst
If intGallery = "" Then intGallery = rs("gallery_id")
For i = 0 To rs.RecordCount
If Not rs.EOF Then
Response.Write("<option")
If CStr(intGallery) = CStr(rs("gallery_id")) Then
Response.Write (" selected=""selected""")
End If
Response.Write(" value=""" & rs("gallery_id") & """>" & rs("gallery_title") & " (" & rs("imgCount") & ")</option>")
rs.MoveNext
End If
Next
%>
</select>
<input type="submit" value="Go" />
</td>
<td valign="middle" class="gallery_header_right">
</td>
</tr>
<tr>
<td colspan="3" class="gallery_body" valign="top">
<%
Dim rs1, rs2, pageSize, pageCount, intRecordsShown
pageSize = 9
Set rs2 = Server.CreateObject("ADODB.RecordSet")
rs2.Open("SELECT description, gallery_title, gallery_id FROM galleries WHERE gallery_id = " & intGallery), conn, 3
Set rs1 = Server.CreateObject("ADODB.RecordSet")
rs1.pageSize = pageSize
rs1.cacheSize = pageSize
rs1.Open("SELECT image_id, width, height, title, file_path FROM " & _
"images WHERE gallery_id = " & intGallery), conn, adOpenStatic, adLockReadOnly, adCmdText
pageCount = rs1.pageCount
'Response.Write(rs("gallery_title"))
' If pageCount = 0 then
' dispError("No images are currently in this category.")
' End If
'|Prevent user from going out of scope.
If intPage > pageCount Then intPage = pageCount
If intPage < 1 Then intPage = 1
Response.Write("<div class=""gallery_body_top"">" & _
"<span style=""font-weight: bold;"">" & _
rs2("gallery_title") & "</span> (<span style=""color: #bc1212;"">" & rs1.RecordCount & " " & getPlural("image", rs1.RecordCount) & " | Page " & intPage & " of " & pageCount & "</span>)")
Response.Write("<br />" & rs2("description") & "</div>")
Response.Write("<div class=""gallery_body_bottom"">")
%>
<script language="JavaScript" type="text/javascript">
<!--
//Opens a new window with the specified properties.
function openWin(pageHref, pageName, pageWidth, pageHeight)
{
var center_t = (screen.height - pageHeight) / 2;
var center_l = (screen.width - pageWidth) / 2;
props = 'height=' + pageHeight + ' ,width=' + pageWidth+' ,top=' + center_t+' ,left=' + center_l+' ,scrollbars=yes ,noresize';
show = window.open(pageHref, pageName, props);
show.window.focus();
return false;
}
//-->
</script>
<table summary="gallery body" cellpadding="0" cellspacing="5">
<tr>
<%
rs1.absolutePage = intPage
intRecordsShown = 0
Do While intRecordsShown < pageSize And Not rs1.EOF
If intrecordsShown Mod 3 = 0 And intRecordsShown > 0 Then Response.Write("</tr><tr>") End If
%>
<td class="gallery_image_cell"><a onclick="return openWin(this.href, 'view_image', <%= rs1("width")+33 %>, <%= rs1("height")+75 %>);" href="view_image.asp?image_id=<%= rs1("image_id") %>"><img class="gallery_image" src="<%= getFileName(rs1("file_path")) %>" alt="<%= rs1("title") %>" /></a></td>
<%
intRecordsShown = intRecordsShown + 1
rs1.MoveNext
Loop
%>
</tr>
</table>
<%
Response.Write("</div>")
%>
</td>
</tr>
<tr>
<td valign="middle" colspan="2" class="gallery_footer">
<span style="font-weight: bold;">Pages: (
<%
Dim x
For x = 1 To pageCount
Response.Write("<a class=""link_red"" href=""" & Request.ServerVariables("SCRIPT_NAME") & _
"?gallery_id=" & rs2("gallery_id") & "&page=" & x & """>" & x & "</a>")
If x < pageCount Then Response.Write(", ")
Next
%>
)</span>
</td>
<td class="gallery_footer" align="right" style="padding-right: 3px;">
<a href="admin/" class="link_red">Admin</a>
</td>
</tr>
</table>
</form>
</div>
<br><br><br>
<div class="buntine">
<p><br>
Image gallery powered by software from <a target="blank" href="http://andrewbuntine.com">Andrew Buntine</a>
<br></p>
</div>
<!--#include virtual="/header.inc" -->
<!--#include virtual="/footer.inc" -->
<%
rs.Close
rs1.Close
rs2.Close
%>
Any help will be great as to why it does not load the requested page, i have been trying to figure this out for ages
Thanks
Can anybody help with this coding, it is the image gallery offered up by Buntine, the only thing is,
when more than 9 pictures are in one category it creates a new page with a link at the bottom i.e Page (1,2,3....). When clicking on the link for a particular page the gallery category is requested along with the page id, i.e. gallery_id=3&page=1 but the page returned when 'page=?' is present in the menu bar is always the last page in the category.
The code for the page is;
<!-- #include file="includes/adovbs.inc" -->
<!-- #include file="includes/conn.asp" -->
<%
Dim rs, sql, i
Dim intGallery, intPage
intGallery = Request.QueryString("gallery_id")
intPage = nvl(Request.QueryString("page"), 1)
Public Function getFileName(strFile)
Dim strExt, strAddon
strAddon = "_small"
strExt = Right(strFile, 4)
getFileName = Left(strFile, Len(strFile) - 4) & _
strAddon & strExt
End Function
Public Function getPlural(str, count)
If count > 1 Then
getPlural = str & "s"
Else
getPlural = str
End If
End Function
Set rs = Server.CreateObject("ADODB.RecordSet")
sql = "SELECT g.gallery_id, g.gallery_title, COUNT(i.image_id) AS imgCount FROM galleries g, images i WHERE " & _
"i.gallery_id = g.gallery_id GROUP BY g.gallery_id, g.gallery_title;"
rs.Open(sql), conn, 3
If rs.EOF And rs.BOF Then
dispError("No records returned. Please try again")
End If
%>
<link rel="stylesheet" type="text/css" href="styles/generic.css"></link>
<!--#include virtual="/head.inc" -->
<div align="center" style="margin-top: 20px;">
<form action="<%= Request.ServerVariables("SCRIPT_NAME") %>" method="get">
<table class="gallery" cellspacing="0">
<tr>
<td valign="middle" class="gallery_header_left">Galleries: </td>
<td valign="middle" class="gallery_header_center">
<select name="gallery_id">
<%
rs.MoveFirst
If intGallery = "" Then intGallery = rs("gallery_id")
For i = 0 To rs.RecordCount
If Not rs.EOF Then
Response.Write("<option")
If CStr(intGallery) = CStr(rs("gallery_id")) Then
Response.Write (" selected=""selected""")
End If
Response.Write(" value=""" & rs("gallery_id") & """>" & rs("gallery_title") & " (" & rs("imgCount") & ")</option>")
rs.MoveNext
End If
Next
%>
</select>
<input type="submit" value="Go" />
</td>
<td valign="middle" class="gallery_header_right">
</td>
</tr>
<tr>
<td colspan="3" class="gallery_body" valign="top">
<%
Dim rs1, rs2, pageSize, pageCount, intRecordsShown
pageSize = 9
Set rs2 = Server.CreateObject("ADODB.RecordSet")
rs2.Open("SELECT description, gallery_title, gallery_id FROM galleries WHERE gallery_id = " & intGallery), conn, 3
Set rs1 = Server.CreateObject("ADODB.RecordSet")
rs1.pageSize = pageSize
rs1.cacheSize = pageSize
rs1.Open("SELECT image_id, width, height, title, file_path FROM " & _
"images WHERE gallery_id = " & intGallery), conn, adOpenStatic, adLockReadOnly, adCmdText
pageCount = rs1.pageCount
'Response.Write(rs("gallery_title"))
' If pageCount = 0 then
' dispError("No images are currently in this category.")
' End If
'|Prevent user from going out of scope.
If intPage > pageCount Then intPage = pageCount
If intPage < 1 Then intPage = 1
Response.Write("<div class=""gallery_body_top"">" & _
"<span style=""font-weight: bold;"">" & _
rs2("gallery_title") & "</span> (<span style=""color: #bc1212;"">" & rs1.RecordCount & " " & getPlural("image", rs1.RecordCount) & " | Page " & intPage & " of " & pageCount & "</span>)")
Response.Write("<br />" & rs2("description") & "</div>")
Response.Write("<div class=""gallery_body_bottom"">")
%>
<script language="JavaScript" type="text/javascript">
<!--
//Opens a new window with the specified properties.
function openWin(pageHref, pageName, pageWidth, pageHeight)
{
var center_t = (screen.height - pageHeight) / 2;
var center_l = (screen.width - pageWidth) / 2;
props = 'height=' + pageHeight + ' ,width=' + pageWidth+' ,top=' + center_t+' ,left=' + center_l+' ,scrollbars=yes ,noresize';
show = window.open(pageHref, pageName, props);
show.window.focus();
return false;
}
//-->
</script>
<table summary="gallery body" cellpadding="0" cellspacing="5">
<tr>
<%
rs1.absolutePage = intPage
intRecordsShown = 0
Do While intRecordsShown < pageSize And Not rs1.EOF
If intrecordsShown Mod 3 = 0 And intRecordsShown > 0 Then Response.Write("</tr><tr>") End If
%>
<td class="gallery_image_cell"><a onclick="return openWin(this.href, 'view_image', <%= rs1("width")+33 %>, <%= rs1("height")+75 %>);" href="view_image.asp?image_id=<%= rs1("image_id") %>"><img class="gallery_image" src="<%= getFileName(rs1("file_path")) %>" alt="<%= rs1("title") %>" /></a></td>
<%
intRecordsShown = intRecordsShown + 1
rs1.MoveNext
Loop
%>
</tr>
</table>
<%
Response.Write("</div>")
%>
</td>
</tr>
<tr>
<td valign="middle" colspan="2" class="gallery_footer">
<span style="font-weight: bold;">Pages: (
<%
Dim x
For x = 1 To pageCount
Response.Write("<a class=""link_red"" href=""" & Request.ServerVariables("SCRIPT_NAME") & _
"?gallery_id=" & rs2("gallery_id") & "&page=" & x & """>" & x & "</a>")
If x < pageCount Then Response.Write(", ")
Next
%>
)</span>
</td>
<td class="gallery_footer" align="right" style="padding-right: 3px;">
<a href="admin/" class="link_red">Admin</a>
</td>
</tr>
</table>
</form>
</div>
<br><br><br>
<div class="buntine">
<p><br>
Image gallery powered by software from <a target="blank" href="http://andrewbuntine.com">Andrew Buntine</a>
<br></p>
</div>
<!--#include virtual="/header.inc" -->
<!--#include virtual="/footer.inc" -->
<%
rs.Close
rs1.Close
rs2.Close
%>
Any help will be great as to why it does not load the requested page, i have been trying to figure this out for ages
Thanks