navigation
a webmaster learning community
     Home    Register     Search      Help      Login    
Sponsors

Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions.

Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax

Search Forums
 

Advanced search
Recent Posts

 Todays Posts
 Most Active posts
 Posts since last visit
 My Recent Posts
 Mark posts read

Microsoft MVP

 

Creating a Random Record?

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> ASP and Database >> Creating a Random Record?
Page: [1]
 
jorkel

 

Posts: 7
From: Kansas City, MO USA
Status: offline

 
Creating a Random Record? - 3/4/2001 15:14:00   
I would like to create a query that randomly selects a title and image from an Access DB and posts it to the page.

How easy is this to do with FP and how do I do it?

Guest


 
RE: Creating a Random Record? - 3/4/2001 16:10:00   
Paste the following function in a new module.

Function Randomizer () As Integer
Static AlreadyDone As Integer
If AlreadyDone = False Then Randomize : AlreadyDone = True
Randomizer = 0
End Function


Now to get 100 myitems picked at random:

SELECT TOP 100 mytable.*
FROM mytable
WHERE (((randomizer())=0))
ORDER BY Rnd(IsNull( mytable.myitem)*0+1);

You swap mytable for your table name and myitem for the your field name. Change 100 to what ever amount you want to return.

EE


(in reply to jorkel)
jorkel

 

Posts: 7
From: Kansas City, MO USA
Status: offline

 
RE: Creating a Random Record? - 3/4/2001 16:48:00   
probably a really dumb question but what's a module? :-)

(in reply to jorkel)
Elecia

 

Posts: 68
From: orlando
Status: offline

 
RE: Creating a Random Record? - 3/4/2001 17:21:00   
You should see a tab for modules in your access database just like the query,report,table and form tabs. By the way it makes absolutely no difference what the module is named you can leave it at the default value of Module1 if you like. Let me know if you need more info.

(in reply to jorkel)
jorkel

 

Posts: 7
From: Kansas City, MO USA
Status: offline

 
RE: Creating a Random Record? - 3/4/2001 22:58:00   
I put the module in but when I tried to put into the ASP, I get this error:

[Microsoft][ODBC Microsoft Access Driver] Undefined function 'randomizer' in expression.

The statement shoul look like this, right? (HeSaidSheSaid is the table)

SELECT TOP 100 HeSaidSheSaid.*
FROM HeSaidSheSaid
WHERE (((randomizer())=0))
ORDER BY Rnd(IsNull(HeSaidSheSaid.Title)*0+1);


(in reply to jorkel)
Elecia

 

Posts: 68
From: orlando
Status: offline

 
RE: Creating a Random Record? - 3/5/2001 20:25:00   
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>
<BODY>

<%

Dim objConn
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=C:\Documents and Settings\Administrator\Desktop\DF\DrawFlowApplication_Local\fpnwind.mdb;"
objConn.Open

Dim objRS
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open "SELECT employees.* FROM employees", objConn, _
adOpenStatic, adLockReadOnly

Dim rndMax
rndMax = CInt(objRS.RecordCount)
objRS.MoveFirst

'Do until objRS.EOF
' Response.Write objRS("lastname") & "<BR>"
'objRS.MoveNext
'loop

objRS.MoveFirst

Dim rndNumber
Randomize Timer
rndNumber = Int(RND * rndMax)

objRS.Move rndNumber

Response.Write objRS("lastname")


%>
<BR>
<table border=1>
<tr>
<td>  <%= objRS("lastname")%> </td>
<td>  <%= objRS("firstname")%> </td>
</tr>

O.K. forget the previous posts I misunderstood where you were trying to query from. I thought you were just writing a query in the database itself. You can take the code below change the cnstring to reflect the location of your database and you will need to replace the table and fields names that are referred to through out the rest of the code. This sample writes the last name out the page both in plain text and to table.
EE

<%
objRS.Close
Set objRS = Nothing

objConn.Close
Set objConn = Nothing
%>
</table>
</BODY>
</HTML>


(in reply to jorkel)
Page:   [1]

All Forums >> Web Development >> ASP and Database >> Creating a Random Record?
Page: [1]
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts