Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ASP / Database Access / February 2007



Tip: Looking for answers? Try searching our database.

query not ranomizing records in ASP - Access 2000  web application

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
hardik - 24 Feb 2007 09:33 GMT
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
Bob Barrows [MVP] - 24 Feb 2007 12:32 GMT
> Hi friends,
>
[quoted text clipped - 21 lines]
> 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

Signature

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 - 24 Feb 2007 14:31 GMT
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] - 24 Feb 2007 14:38 GMT
> thanks Bob Barrows [MVP]
>
[quoted text clipped - 6 lines]
> 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) &
[quoted text clipped - 3 lines]
>
> could it be the problem of connection ?

Nope. Totally irrelevant. Er ... you don't only have three records in that
table do you? ;-)

Signature

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 - 24 Feb 2007 17:46 GMT
> thanks Bob Barrows [MVP]
>
[quoted text clipped - 12 lines]
>   "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
hardik - 27 Feb 2007 14:43 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.