Displaying Random records From a database

Results 1 to 2 of 2

Thread: Displaying Random records From a database

  1. #1
    Durgesh Guest

    Default Displaying Random records From a database

    Hi<BR><BR>i want to display different record from a database randomly each time the user queries the same database <BR>i found out a script which does that but<BR>i want to show all the records differently but this script does only for one record<BR><BR>Here is the script<BR>&#060;%<BR>Dim intMax &#039 For Counting Records<BR>Dim rndNumber &#039 For Random Number generator <BR> strSQL=" select gb_id from guest_book " <BR> Set ArtMecca = Server.CreateObject("ADODB.Connection")<BR> ArtMecca.ConnectionTimeout = Session("ArtMecca_ConnectionTimeout")<BR> ArtMecca.CommandTimeout = Session("ArtMecca_CommandTimeout")<BR> ArtMecca.Open Session("ArtMecca_ConnectionString"), Session("ArtMecca_RuntimeUserName"), Session("ArtMecca_RuntimePassword")<BR> Set cmdTemp = Server.CreateObject("ADODB.Command")<BR> Set rsGuestbook = Server.CreateObject("ADODB.Recordset")<BR> cmdTemp.CommandText = strSQL<BR> cmdTemp.CommandType = 1<BR> Set cmdTemp.ActiveConnection = ArtMecca<BR> rsGuestbook.Open cmdTemp, , 1, 1<BR><BR>On Error Resume Next<BR><BR> If rsGuestbook.BOF And rsGuestbook.EOF Then <BR> gbEmptyRecordset = True<BR> Else<BR> intMax = CInt(rsGuestbook.RecordCount)<BR> End If <BR> rsGuestbook.MoveFirst<BR> Do WHile Not rsGuestbook.EOF<BR> Response.Write rsGuestbook("gb_id") & "<BR>" <BR> rsGuestbook.MoveNext<BR> LOOP<BR>rsGuestbook.MoveFirst <BR>Rem ----------------------------------------------------------<BR>Rem Random function<BR>Rem------------------------------------------------------------<BR> Randomize Timer<BR> rndNumber = Int(RND * intMax) <BR> rsGuestbook.Move rndNumber<BR>Response.Write "&#060;HR&#062; "<BR>Response.Write rsGuestbook("gb_id") <BR> rsGuestbook.Close<BR> Set rsGuestbook = Nothing<BR> objConn.Close <BR> Set objConn = Nothing<BR>%&#062;<BR><BR>

  2. #2
    Larry Boggs Guest

    Default RE: Displaying Random records From a database

    Check this out and see if it works for you!<BR><BR>www.mahcsp.com/demo/default.asp<BR><BR>I just got it working (I&#039ve been trying to figure this out for some time now!)<BR><BR>See Ya,<BR>Larry Boggs<BR>lboggs@i1.net

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •