Signup · Login
Stardeveloper.com  
Home · Tutorials · Forums · Web Hosting Plans · Faisal Khan's Blog · Contact
Forums : ASP : ADO/ODBC : random records Signup · Login
Author Thread
random records
Posted in tutorial: Generating Random Records from the Database
·  rbknll
User
Joined: 12 Feb 2004
Total Posts: 1
random records
Posted: 12 Feb 2004
this script is great, I modified it to output a table with to fields.
can you help me make the total number of records NOT LESS than 6 or 8 ?

here is what I did:
<%
Option Explicit
Response.Buffer = True
%>
<html>
<head>
<style>
p { font-family:verdana; font-size:11px; }
</style>
</head>
<body>
<br><p align="center">
<%
' ADO Constant. Dont change this
Const adCmdText = &H0001

%>
<CENTER>
<FONT FACE='Verdana'>
<TABLE BORDER=1 CELLPADDING=2 CELLSPACING=0 style="border-collapse: collapse" bordercolor="#111111">
<TR BGCOLOR=#000080>
<TD ALIGN=CENTER bgcolor="#C0C0C0">
<FONT COLOR=#FFFFFF SIZE=2>
A
</FONT>
</TD>
<TD ALIGN=CENTER bgcolor="#C0C0C0">
<FONT COLOR=#FFFFFF SIZE=2>
B
</FONT>
</TD>
</TR>

<%
' Connection string and SQL statement
Dim query, connStr
query = "select company_name,company_toll from table2"
connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
Server.MapPath("guestbook.mdb")

' Opening database
Dim rs
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open query, connStr, 3, , adCmdText

' Generating random number from total number of records
Dim intRnd
Randomize Timer
intRnd = (Int(rs.RecordCount*rnd))
rs.Move intRnd

'Loop through the recordset
Do While not rs.EOF
%>
<TR>
<TD>
<FONT SIZE=1>
<%Response.Write rs("company_name") %>
</FONT>
 </TD>
<TD>
<FONT SIZE=1>
<%Response.Write rs("company_toll") %>
</FONT>
 </TD>
</TR>

<%
'Move to the next record in the recordset
rs.MoveNext
Loop






' Closing the database
rs.Close
Set rs = Nothing
%>
</TABLE>
</p>
</body>
</html>

Users Who Have Visited This Thread In Last 24 Hours
2 Visitors

Login
UserName Or Email Address:       Password:       Auto-Login:    
· Create New User Account
· Send Forgotten Password by Email
 
© 1999 - 2009 Stardeveloper.com, All Rights Reserved.