Groups | Blog | Home
all groups > inetserver asp db > february 2007 >

inetserver asp db : query not ranomizing records in ASP - Access 2000 web application


Bob Barrows [MVP]
2/24/2007 12:00:00 AM
[quoted text, click to view]
Try thisw instead:

http://www.adopenstatic.com/faq/RandomRecord.asp

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

hardik
2/24/2007 1:33:55 AM
Hi friends,

can anyone solve this query ?

I have a table which stores products id and name and then product
image now all i want is everytime i refresh a page it should display 5
diffrent images then last one

I have almost 500 records in product_master table.

here is my product_master table

pid (Autonumber) pname pimage

1 abc 1.gif
2 xyz 2.png

now from site,

http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_208...

i got this query to generate random and unique records

query = "SELECT TOP 5 Rnd(pid) AS Expr1, product_master.Text1,
product_master.Text2 FROM product_master ORDER BY Rnd(pid)"

set productimage=server.CreateObject("adodb.recordset")

productimage query,conn
do while not productimage.eof

%>
<img align="center" src="<%="images/" &
productimage.fields("imagepath")%>" border="0" />
<%

productimage.next
loop

set productimage = nothing

my query runs fine and output also shown in five records but it never
comes random always the same i need to change 5 images everytime page
refreshes,

Thank You In Advance,

Have a good day

Best Of Luck
hardik
2/24/2007 6:31:44 AM
thanks Bob Barrows [MVP]

it's not working i have tried

can you plz tell me what will be the problem

here is the query,


Randomize()
intRandomNumber = Int (1000*Rnd)+1

strSQL = _
"SELECT TOP 4 id, name,image, Rnd(" & -1 * (intRandomNumber) &
"*id)" & _
"FROM products " & _
"ORDER BY 3"


could it be the problem of connection ?


here is my connection file

set conn = server.createobject("adodb.connection")
connstr = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" &
server.mappath("../private/dbase.mdb")
conn.open connstr

Bob Barrows [MVP]
2/24/2007 9:38:13 AM
[quoted text, click to view]

Response.Write the number to make sure you are getting a different one each
time the page runs:

Response.Write intRandomNumber

[quoted text, click to view]
Nope. Totally irrelevant. Er ... you don't only have three records in that
table do you? ;-)

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Mike Brind
2/24/2007 5:46:46 PM

[quoted text, click to view]

Change it to read ORDER BY 4. That's the ordinal position of the field to
order by (the random number), which in the example was the third field,
whereas in your, it's the 4th. Your third field is image. so currently it
will always return the row with the image that is alphabetically first.

--
Mike Brind

hardik
2/27/2007 6:43:59 AM
hi friends finally this thing work for me


Randomize()
intRandomNumber = Int (1000*Rnd)+1

strSQL = _
"SELECT TOP 4 pid, pname,image, Rnd(" & -1 * (intRandomNumber) &
"*pid)" & _
"FROM product_master " & _
"ORDER BY 4"


it perfectly works for me


Thank you all of you persons


AddThis Social Bookmark Button