| Author |
Topic Search Topic Options
|
zMaestro
Senior Member
Joined: 11 May 2003
Location: Egypt
Status: Offline
Points: 1183
|
Post Options
Thanks(0)
Quote Reply
Topic: Random Selection from Database Posted: 16 April 2004 at 10:07am |
Hi
I use this code to select a random image from a database.
<% Rand = "SELECT * FROM TableName" set RandS = server.createobject("adodb.recordset") RandS.open Rand, Conn, 3, 1
rndMax = CInt(RandS.RecordCount) RandS.MoveFirst Randomize Timer rndNumber = Int(RND * rndMax) RandS.Move rndNumber
RandHere = RandHere & "<IMG src=""" & RandS("Image") & """>" %>
|
Is there a way i can select 4 random images instead of only one image.
thanks.
Edited by zMaestro
|
 |
Mart
Senior Member
Joined: 30 November 2002
Status: Offline
Points: 2304
|
Post Options
Thanks(0)
Quote Reply
Posted: 16 April 2004 at 10:16am |
Try this:
<% Rand = "SELECT * FROM TableName" set RandS = server.createobject("adodb.recordset") RandS.open Rand, Conn, 3, 1
Dim i
For i = 1 To 4
rndMax = CInt(RandS.RecordCount) RandS.MoveFirst Randomize Timer rndNumber = Int(RND * rndMax) RandS.Move rndNumber
RandHere = RandHere & "<IMG src=""" & RandS("Image") &
""">"
Next i
%>
|
 |
zMaestro
Senior Member
Joined: 11 May 2003
Location: Egypt
Status: Offline
Points: 1183
|
Post Options
Thanks(0)
Quote Reply
Posted: 16 April 2004 at 10:36am |
hmm, i am not familiar with For NExt statment.. it gives me:
Error Type: Microsoft VBScript compilation (0x800A0401) Expected end of statement /Home.asp, line 390, column 5 Next y ----^
|
|
 |
Mart
Senior Member
Joined: 30 November 2002
Status: Offline
Points: 2304
|
Post Options
Thanks(0)
Quote Reply
Posted: 16 April 2004 at 10:40am |
|
delete the y so it is just Next, I wasn't sure if you had to use 'Next [var]' in Classic ASP.
|
 |
zMaestro
Senior Member
Joined: 11 May 2003
Location: Egypt
Status: Offline
Points: 1183
|
Post Options
Thanks(0)
Quote Reply
Posted: 16 April 2004 at 10:41am |
Ohh Thanks Mart.. it worked 
Edited by zMaestro
|
 |
ljamal
Mod Builder Group
Joined: 16 April 2003
Status: Offline
Points: 888
|
Post Options
Thanks(0)
Quote Reply
Posted: 16 April 2004 at 10:57am |
|
If you are using SQL Server the following will produce records in random order
select * from table order by NewID()
|
|
|
 |
vinoth
Newbie
Joined: 24 April 2003
Location: India
Status: Offline
Points: 26
|
Post Options
Thanks(0)
Quote Reply
Posted: 17 April 2004 at 5:54am |
Cool And Great Developers All Here in Asp,
But I am In PHP
|
 |
ljamal
Mod Builder Group
Joined: 16 April 2003
Status: Offline
Points: 888
|
Post Options
Thanks(0)
Quote Reply
Posted: 17 April 2004 at 9:30am |
vinoth wrote:
Cool And Great Developers All Here in Asp,
But I am In PHP |
because this is forum for ASP
there are many PHP development forums, go check those out
that's saying this is a great hamburger restaurant but I want a steak.
|
|
|
 |