query not ranomizing records in ASP - Access 2000 web application

query not ranomizing records in ASP - Access 2000 web application

am 24.02.2007 10:33:55 von hardik

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_Acc ess/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

%>
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

Re: query not ranomizing records in ASP - Access 2000 web application

am 24.02.2007 13:32:12 von reb01501

hardik wrote:
> 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_Acc ess/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)"
>

> 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,
>
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"

Re: query not ranomizing records in ASP - Access 2000 web application

am 24.02.2007 15:31:44 von hardik

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

Re: query not ranomizing records in ASP - Access 2000 web application

am 24.02.2007 15:38:13 von reb01501

hardik wrote:
> 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

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

Response.Write intRandomNumber

>
> strSQL = _
> "SELECT TOP 4 id, name,image, Rnd(" & -1 * (intRandomNumber) &
> "*id)" & _
> "FROM products " & _
> "ORDER BY 3"
>
>
> could it be the problem of connection ?
>
>
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"

Re: query not ranomizing records in ASP - Access 2000 web application

am 24.02.2007 18:46:46 von Mike Brind

"hardik" wrote in message
news:1172327503.981980.98040@8g2000cwh.googlegroups.com...
> 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"
>
>

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

Re: query not ranomizing records in ASP - Access 2000 web application

am 27.02.2007 15:43:59 von hardik

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