By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,395 Members | 2,537 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,395 IT Pros & Developers. It's quick & easy.

next record link

100+
P: 229
Hi, I wonder if anyone could point me in the right direction. I have this script that gets a random record from my database. All records have an id, how do I instead of random just go to the next record?
Any pointers would be great.
Thanks
Richard


Expand|Select|Wrap|Line Numbers
  1. <% 
  2. ' ADO Constant. Dont change this 
  3. ' Connection string and SQL statement 
  4.  
  5. sql  = "Select artist,largeimageseven  FROM tblGreet where largeimageseven = 'yes'"
  6. connStr = " Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("/fpdb/greetingcardpro.mdb" ) 
  7. ' Opening database 
  8.  
  9. Set rs = Server.CreateObject("ADODB.Connection")
  10. Set rs = Server.CreateObject("ADODB.Recordset")
  11. rs.Open sql, connStr, 3, , adCmdText 
  12. ' Generating random number from total number of records 
  13.  
  14. Randomize Timer 
  15. intRnd = (Int(RND * rs.RecordCount)) 
  16. ' Now moving the cursor to random record number 
  17. rs.Move intRnd 
  18. ' Showing the random statement 
  19. Response.Write "<span span style=""float: right;""><a href=""/artist.asp?artist=" & rs("artist") & """>next&nbsp; <img src=""plusright.gif"" border=""0""></a></span>"
  20. ' Closing the database 
  21. rs.Close 
  22. Set rs = Nothing 
  23. %>
Aug 2 '08 #1
Share this Question
Share on Google+
2 Replies


idsanjeev
100+
P: 241
Hello
Add order by in sql statement to arrange your records with id or other column wise.
like-
Expand|Select|Wrap|Line Numbers
  1. sql=selec *from  tablename where column=columnname order by columnname
regards
jha
Aug 4 '08 #2

DrBunchman
Expert 100+
P: 979
Hi Richard,

Use
Expand|Select|Wrap|Line Numbers
  1. rs.MoveNext
to move to the next record.

Hope this helps,

Dr B
Aug 4 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.