View Full Version : Quick One For You!
Hi there
I wish have a recordset produce a random record every time the page is opened.
Simply just a random number on the link to the page and have the recordset pull the url vairable and then get a record.
I can do this but what i want to do is have the recordset pull a record for an entered vaule and instead of typing in a value.
I want to put in the code for a random number i remeber seing a bit of code like like var(0-250) and this would give you a random number between 1 and 250.
Does anyone no the little bit of code that will do this?
I am using dreaded old access 2000 for this one not my trusty sql2000 which is half the problem.
I would be greatful very greatful for the help.
:confused: :confused: :confused: :confused: :confused:
BigDaddy
11-29-2002, 12:30 AM
Get a random # this way:
<% @Language="VBScript" %>
<% randomize()
randomNumber=Int(250 * rnd())
%>
The random # is: <%= randomnumber%>
Then do a select to get a corresponding record on a unique field, such as "counter" -- or a primary key where every record will have its own distinct #.
"Select * from FOOFERNARGEN where counter = '" & randomNumber & '""
Adjust the number 250 above to whatever range you want.
whammy
11-29-2002, 02:31 AM
FOOFERNARGEN ?!? :D
And I thought I picked silly names for things sometimes... ;)
BigDaddy
11-29-2002, 05:11 AM
FOOFERNARGEN works. :)
whammy
11-29-2002, 05:13 AM
Perhaps you have watched too many Volkswagen commercials in an altered state? ;)
Hehehe...
Hi there
I tried the randomize code bigdaddy suggested and it cam up with this error when i ran the page.
Microsoft VBScript compilation error '800a03ea'
Syntax error
/employeeDevelopment/XP1/www/pages/TMPvii6s6bz2m.asp, line 9
foe.Source = "SELECT * FROM foe WHERE foeID = '"& randomNumber & '""
-------------------------------------------------------------------^
Here is the code on my page:
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="../../Connections/XP1.asp" -->
<%
randomize()
randomNumber=int(6 * rnd()) %>
<%
set foe = Server.CreateObject("ADODB.Recordset")
foe.ActiveConnection = MM_XP1_STRING
foe.Source = "SELECT * FROM foe WHERE foeID = '"& randomNumber & '"""
foe.CursorType = 0
foe.CursorLocation = 2
foe.LockType = 3
foe.Open()
foe_numRows = 0
%>
<html>
<head>
I have tried to remove some of the speach marks and still can't get it to work.
Any suggestions.??
All i want is this recordset to load up with a random record everytime so you never know what to expect when you land on this page. Could be nice little puppies could be a nasty monster.
who knows the page decides.
:confused: :confused: :confused:
BigDaddy
11-29-2002, 03:28 PM
It's hard to see w/out pasting the line of code into another program, but I dropped the line in question into HTML-Kit, and it looks like you had the ' and the " in the wrong order at the end of your sql statement.
Try:
foe.Source = "SELECT * FROM foe WHERE foeID = '"& randomNumber & "'"
hi there
I tried to swap them round and got a similar error.
I thought possible using a java script to generate the random number in a similar fashion to the way suggested here and then just putting the code as in above.
But this presents the problem of that the java script would need to run before the server executed the page so the random number was produced.
if you know what i am doing it might help understand the problem.
I have a page that loads up with the detals of the user held in sessions.
this page has seperate frames one showing two graphics and info pulled from the database using one of the sessions for the user.
the other image and info i want to pull form the foe table in my database, this i want to be random so everytime they come accross this page the info pulled from the foe table is random, these are then converted to sessions.
This way the user never knows what to expect when they come to this page.
The secound frame has a script that adds a few of the sessions for the user together and then subtracts them from the sessions for the foe generated out of the database.
this then updates the foe sessions and displays them accordingly under the image.
this is also done for the foe where some of its sessions are added up and deducted for the users info and sessions updated accordily so by the time the page has loaded everything both the users and the foes info has changed in the first frame.
The second frame has a form on it that when submitted refreshes the first frame and recalulates the figures and so on.
The problem i am having is getting the recordset for the foe to pull a random record. If i put a link to this page i can put the random record on the link as i have a extension for dreamweaver that showed me the code for doing this.
The problem there is that the user will know where this page appears by the link if they hover of it and as most of the links are dynamicly generated out of the database it gets rather complicated.
So the easiest solution i though would be to get the foe recordset to produce the random number the first time the page loads then convert the vaules into session variables and then it doesn't matter if the recordset keeps coming upwith a random figure every time ans the code for the set sessions is in a conditional region that will only show if the foeID session is empty and their is a bit of code that empties the sessions for the foe so the next time the user lands on the page.
its a rpg for the kids with simple graphics and plot. being done out of the database that can grow as i add stuff to it.
vBulletin® v3.8.2, Copyright ©2000-2010, Jelsoft Enterprises Ltd.