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!

next previous 1

Status
Not open for further replies.

matrix07

Programmer
Mar 21, 2002
41
CA
hi...I'm trying to do an image gallery with next and previous links. The way I'm doing it is I'm comparing my querystring to my primary ID in my database...so for example...default.asp?rec=1 I tell it to get all the images whose primaryID is larger than the querystring. it's been awhile since I've done ASP. Can I compare autonumbers to numbers??? I'm getting an error for that. here is my code.
Really appreciate it. Thanks. Also how do I pass a value when Default.asp is my start page??? Thanks again.


<%
dim rsImage
dim sql
dim counter
dim limit

sql = &quot;select Top 8 * from tblImages where image_ID > '&quot; & Request.QueryString(&quot;rec&quot;) & &quot;'&quot;

set rsImage = Server.CreateObject(&quot;Adodb.recordset&quot;)
rsImage.Open sql, objConn, adOpenDynamic, adLockReadOnly, adcmdText

limit = 5
counter = 1

do while not rsImage.EOF
if counter = 1 then
Response.Write &quot;<tr>&quot;
end if%>
<td><a href=&quot;<%=rsImage(&quot;image_large&quot;)%>&quot; target=&quot;_blank&quot;><img src=&quot;<%=rsImage(&quot;image_small&quot;)%>&quot; style=&quot;filter:alpha(opacity=50)&quot; onmouseover=&quot;nereidFade(this,100,30,5)&quot; onmouseout=&quot;nereidFade(this,50,50,5)&quot;></a>
</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<%counter = counter + 1
if counter = limit then
Response.Write &quot;</tr>&quot;
counter = 1
end if
rsImage.MoveNext
loop
%>
<tr>
<td></td>
<td height=&quot;20&quot;></td>
</tr>
<tr><td><a href=&quot;Default.asp?rec=<%=Request.QueryString(&quot;rec&quot;)%>&quot;>next</a></td></tr>
</table>
 
Hi,
Yes of course that you can compare them.
And the method that you choose is the right one (transmitting in querystring the ID of item that you want to be selected from table).
I don't know what error you have. There should be no erors. Eventually when you check if you reach the EOF or the begining.
I will do this like this: normally, if you have some links in page like: <<prev or next>>, then show them just in case that the next/previous record exist (check if recordset for ID+/-1 is empty).
Also, you have to treat if the ID will not return an empty recordset.
How to pass value for default.asp?
I advice you to have something like:
if request.querystring(&quot;ID&quot;)=&quot;&quot; then response.redirect(&quot;default.asp?ID=x&quot;). Or assign a variable at the begining with the value of Request.Querystring, and of course you can have what default value you want.

Gia Betiu
m.betiu@chello.nl
Computer Eng. CNE 4, CNE 5
 
Look no further! I have created a system to do this without the need for reloading the page. Your recordset is turned into a javascript array and your next/previous buttons load the next image into the page - no reloading!

Have a look at

Thread333-233415

which outlines what to do and

Thread248-230355

which is the &quot;long winded&quot; version. Go to the bottom parts of the thread Derren
[Mediocre talent - spread really thin]
 
A simpler answer:

the reason you're getting an error when comparing the querystring to the autonmuber might be that querystring variables are generally stored as string variables.

Try: sql = &quot;select Top 8 * from tblImages where image_ID > '&quot; & CInt(Request.QueryString(&quot;rec&quot;)) & &quot;'&quot;

CInt turns the string variable into an integer. If the number could contain a decimal place then you should use CDbl instead.
 
thanks guys for the replies. Hey Derren, will definitely check those threads. I don't know much about JavaScript so I might stick with this method for now. Thanks guys.
 
hmmm I still get a type mismatch??? Even though I use the CInt() function??? Here's my error. Thanks.



Microsoft JET Database Engine error '80040e07'
Data type mismatch in criteria expression.


 
matrix...
I appears as though you're loading several pictures at once. If this is the case, why wouldn't you use recordset paging to display your images and keep track of the 'page' you're on within the database to display the appropriate previous-next links rather than comparing the autonumber each time? If I'm correct in the way you're doing this, then you're doing it the hard way..and it's a lot more work for the server as well.

Just curious. -Ovatvvon :-Q
 
Hey Ovatvvon.

I never used Recordset Paging before so that's why I been doing it this way??? Well, I want to load eight images at one time, and if there are more images, I want it to have a next previous link. Can I accomplish this with Paging???
Do you have any code or a way of starting it??? Thanks.
 
There is already a FAQ written by jfriestman on this issue. It is located at: faq333-186

If you have any problems with it, let me know and I will give you a simpler/clearer form of how to do it. -Ovatvvon :-Q
 
Hey Ovatvvon, I got my images displayed and the links work.
But I'm wondering if I am able to add next and previous to the page numbers also??? eg:

PREVIOUS 1 2 3 4 5 NEXT

I will work on it right now and see what I can work out. Here is my code. Thanks again.


<!--#include virtual=&quot;/Reborn/Reborn.inc&quot;-->

<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
</HEAD>
<BODY>

<%
dim rs,i,strConn,strTemp
set rs=server.CreateObject(&quot;adodb.recordset&quot;)

rs.Open &quot;select * from tblImages&quot;,objConn,adOpenStatic, adLockReadOnly, adcmdText

rs.PageSize=8



if Request.QueryString(&quot;pg&quot;)=&quot;&quot; then
rs.AbsolutePage=1
For i=1 to 8
if rs.EOF then
exit for
else
Response.Write &quot;<img src='&quot; & rs(&quot;image_small&quot;) & &quot;'>&quot;
rs.MoveNext
end if
Next
else
rs.AbsolutePage=cint(Request.QueryString(&quot;pg&quot;))
For i=1 to 8
if rs.EOF then
exit for
else
Response.Write &quot;<img src='&quot; & rs(&quot;image_small&quot;) & &quot;'>&quot;
rs.MoveNext
end if
Next
end if

Response.Write &quot;<table><tr>&quot;
for i=1 to rs.PageCount
Response.Write &quot;<td><a href='test.asp?pg=&quot; & i & &quot;'>&quot; & i & &quot;</a></td>&quot;
next
Response.Write &quot;</tr></table><br>&quot;
%>

</BODY>
</HTML>
 
Comepare the total number of pages to the current page you're on. If the current page is less than the maximum pages, then have it display a 'next' link moving the current page up to the next page level. To the same for the previous...if the current page is not the first page in the series, then display the 'previous' link which will take off 1 page level, when clicked, of the current page value.

make sense? -Ovatvvon :-Q
 
ok, I think I got it working properly...will see if I run into any problems...thanks again.
 
hi guys...I have a problem with my next previous links.
The way I have it is if my querystring = &quot;&quot; then input 1 to it. Then I set my absolutepage to what my querystring is which is 1. But when I test it...by just writing what page is on...it is on page 2 of 2??? It should be on page 1 of 2. Any ideas. Here is my code...thanks again...


<%
if Request.QueryString(&quot;pg&quot;) = &quot;&quot; then
Response.Redirect(&quot;Default.asp?pg=1&quot;)
end if
%>

<%
dim counter
dim limit
dim rs,i, max

set rs=server.CreateObject(&quot;adodb.recordset&quot;)

rs.Open &quot;select * from tblImages&quot;,objConn,adOpenStatic, adLockReadOnly, adcmdText
rs.PageSize=8


limit = 5
counter = 1

rs.AbsolutePage=cint(Request.QueryString(&quot;pg&quot;))


do while not rs.EOF
if max = rs.PageSize then
exit do
end if

if counter = 1 then
Response.Write &quot;<tr>&quot;
end if

Response.Write &quot;<td>&quot;
Response.Write &quot;<a href='&quot; & rs(&quot;image_large&quot;) & &quot;' target='_blank'>&quot; & &quot;<img src='&quot; & rs(&quot;image_small&quot;) & &quot;' style='filter:alpha(opacity=50)' onmouseover='nereidFade(this,100,50,30)' onmouseout='nereidFade(this,50,100,30)'>&quot;
counter = counter + 1
max = max + 1

if counter = limit then
Response.Write &quot;</tr>&quot;
counter = 1
end if
rs.MoveNext
loop
%>

<tr>
<td height=&quot;30&quot;></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>


<td BGCOLOR=&quot;white&quot; onMouseOver=&quot;this.style.background='#00FF00'; this.style.cursor='pointer'&quot;
onMouseOut=&quot;this.style.background='white'&quot;>
<%
response.write &quot;page &quot; & rs.absolutepage & &quot;of &quot; & rs.pagecount
'if rs.AbsolutePage < rs.PageCount then
'Response.Write &quot;<p><a href='Default.asp?pg=&quot; & cint(Request.QueryString(&quot;pg&quot;) + 1) & &quot;'>Next</a>&quot;
'else
'Response.Write &quot;<p><a href='Default.asp?pg=&quot; & cint(Request.QueryString(&quot;pg&quot;) - 1) & &quot;'>Previous</a>&quot;
'end if
%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top