Print Page | Close Window

how can i skip to the next user?

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=1755
Printed Date: 29 March 2026 at 12:51am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: how can i skip to the next user?
Posted By: Scotty32
Subject: how can i skip to the next user?
Date Posted: 11 April 2003 at 3:10am

does anyone know the best way i can put a "next" button on a page - to show the next set of details - but not by ID but by the last name

so ya can skip to the next person alphabetaicly?

 




Replies:
Posted By: pmormr
Date Posted: 11 April 2003 at 2:54pm

When you open the recordset use the SQL statement

SELECT * FROM yourfield
FROM yourtable
ORDER BY yourfield asc

not totally positive on my coding but you should get the basic idea... this will order 'yourfield' from 'yourtable' into ascending alphabetical order. now you can use the following HTML statement to move to the next name in the list.

<a href="<%rs.movenext%>">Next name</a>

now, this tells the computer to move to the next record and since they're ordered in alphabetical it moves to the next record. This link needs to be on the same page as the opening calls for the database and sql statement. Something like this

'open your database
'recordset opening call
'html beginning
'your link
'html ending

hope i helped...

Paul Morgan
Webmaster

 

 



-------------
Paul A Morgan

http://www.pmorganphoto.com/" rel="nofollow - http://www.pmorganphoto.com/


Posted By: Scotty32
Date Posted: 14 April 2003 at 4:55am

hi - thanks

umm could ya explain that a lil better cose i dont quite get it

i tryed sum things but with out success

do i put "SELECT * FROM table WHERE field = string ORDER BY lastname" ???

or not

 could i please have sum example code?

(thanks for the help)



Posted By: pmormr
Date Posted: 14 April 2003 at 8:50am

no problem- the only problem with using a "WHERE" clause is that it only selects what it equals. For example: If you have several records, lastnames (to make it easy) 5, 4, 3, 2, and 1, and you use the line "SELECT * FROM yourtable WHERE lastname = 5" then it will only select 5. My suggestion, drop the where clause and only use select and order by. Try this,

"SELECT * FROM yourtable ORDER BY lastname"

then use the link i posted before to move to the next record.

Paul Morgan

 



-------------
Paul A Morgan

http://www.pmorganphoto.com/" rel="nofollow - http://www.pmorganphoto.com/


Posted By: Scotty32
Date Posted: 14 April 2003 at 8:51am
oh, well how will i know which is the next record then?


Posted By: pmormr
Date Posted: 14 April 2003 at 8:53am
because there ordered in alphabetical order according to their lastnames. Try it and see if it works.

-------------
Paul A Morgan

http://www.pmorganphoto.com/" rel="nofollow - http://www.pmorganphoto.com/


Posted By: Scotty32
Date Posted: 14 April 2003 at 8:54am

yeah but i mean, say am on record number 5 how will i know i wanna go to number 6? cose it wont know am on record 5? will it?



Posted By: pmormr
Date Posted: 14 April 2003 at 9:01am

when you select the fields and use a where clause it only selects what you specify in the where clause . for example: you have a table: with one field called 'I' (remember i'm making it simple) the values of i are 1, 2, 3, 4, 5, 6, 7, and 8. if you only select 5 then the computer doesn't worry about 1, 2, 3, 4, 6, 7, and 8. When open up a recordset your basically telling the computer with a WHERE clause that you only need 5. When you say 'rs.movenext' then you hit EOF and you get a falure. If it was imperitive that you start on 5 then you would say:

"SELECT * FROM yourtable"
rs.movefirst
loop = 5
While loop > 0
rs.movenext
Wend

this would take your record pointer and place it on the fifth one in order.



-------------
Paul A Morgan

http://www.pmorganphoto.com/" rel="nofollow - http://www.pmorganphoto.com/


Posted By: pmormr
Date Posted: 14 April 2003 at 9:06am
but still it does know what record you are on because of the other fields. When your use your order by clause it takes the records and places them in order according to the field lastname. It doesn't worry about any of the other fields.

-------------
Paul A Morgan

http://www.pmorganphoto.com/" rel="nofollow - http://www.pmorganphoto.com/


Posted By: Scotty32
Date Posted: 14 April 2003 at 9:10am

yeah i understand wot ya sayin, but wot i mean is, if i put this code on my page... how can i have a "next" and "back" buttons,

cose i'll open the database and show the info for lets say ID 5 but i want to skip to the person next in the line from the Lastname which lets say is id 20, but how will it know to go from 5 to 20?

it sounds like in the thing ya sayin it'll just keep goin thru them from the first person

could i make a new page like "next.asp" but then it wouldnt know i was on fire



Posted By: pmormr
Date Posted: 14 April 2003 at 9:14am

because when you selected with the sql statement it threw them into order by their lastname. back to my example:

ID                LASTNAME
1                 X
2                 M
3                 A

the order by clause puts the lastnames in alphabetical order

ID              LASTNAME
3               A
2               M
1               X

when you say rs.movefirst then it goes to record number 3. when you say rs.movenext it goes to 2 and so on



-------------
Paul A Morgan

http://www.pmorganphoto.com/" rel="nofollow - http://www.pmorganphoto.com/


Posted By: Scotty32
Date Posted: 14 April 2003 at 9:27am

yeah i kinda understand it

but is there anyway i can go to lets say "page.asp?id=2"

and skip from ID 2 to 1? (from your lil table)



Posted By: pmormr
Date Posted: 14 April 2003 at 9:30am

no, you ordered them by lastname



-------------
Paul A Morgan

http://www.pmorganphoto.com/" rel="nofollow - http://www.pmorganphoto.com/


Posted By: Scotty32
Date Posted: 14 April 2003 at 9:34am

do you know wot am tryin to do?

its hard to explain i guess



Posted By: pmormr
Date Posted: 14 April 2003 at 9:36am
no

-------------
Paul A Morgan

http://www.pmorganphoto.com/" rel="nofollow - http://www.pmorganphoto.com/


Posted By: Scotty32
Date Posted: 15 April 2003 at 2:52am

ok so if my table is like this

id            name
-------------------
1                s
2                f
3                b
4                e
5                h
6                a
7                z

can it only go from "id 6" to "id 3" or can i, if am on "id 4" go to "id 2"

becose "id 2" is after "id 4" in the "name" field

wot i want to do is if i go to sumone, id like to be able to get to the next person from the "name" field but so the persons details from there "id"



Posted By: pmormr
Date Posted: 15 April 2003 at 8:55am

i think i got you now... you need to be able to skip by alphabetical order or their id. in that case then you should create two recordsets. Use one recordset with an order by clause and the other with just open. Example:

rsordered.open "SELECT * FROM yourtable ORDER BY lastname", db
rsid.open "SELECT * FROM yourtable", db

all you need to do is have two variables (in this case rsordered and rsid) set to Server.CreateObject(ADODB.Recordset) and you should (provided that your connection to you database is in db) be able to call rsordered.movenext or rsid.movenext and move by lastname or id.



-------------
Paul A Morgan

http://www.pmorganphoto.com/" rel="nofollow - http://www.pmorganphoto.com/



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net