Forums
This topic is locked
Recordset in Random order ?
Posted 23 years ago
1
has voted
23 years ago Stephen Bateman posted:
Is it possible to read a recordset in a random order using MySQL and PHP ? I have a recordset of "banners" that I need to list but want to make sure that they are displayed in a random order so that not only the top ones get clicked.
Any thoughts would be appreciated.
Edited by - GreatTraveller on 09/14/2001 03:16:02
Replies
Replied 23 years ago
23 years ago Tim Green replied:
You really should explore the site a little better.
There is an extension especially for doing this in PHP, available from this site. It is called PHP Move To Random Record and can be found at www.udzone.com/go?834
Tim Green
tim@udzone.com
Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
There is an extension especially for doing this in PHP, available from this site. It is called PHP Move To Random Record and can be found at www.udzone.com/go?834
Tim Green
tim@udzone.com
Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Replied 23 years ago
23 years ago Stephen Bateman replied:
Thanks Tim
I have had a good look over the site and already have download and used sucessfully that extension. It works great.
However I do not see how I could use it to help me display a complete recordset in a random order. Please point me in the right direction if I am just a newbie pain <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
My last question this month I promise.
Stephen
I have had a good look over the site and already have download and used sucessfully that extension. It works great.
However I do not see how I could use it to help me display a complete recordset in a random order. Please point me in the right direction if I am just a newbie pain <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
My last question this month I promise.
Stephen
Replied 23 years ago
23 years ago Tim Green replied:
Actually I think I know what you mean, what you actually want to do is create a recordset that contains one random item from your table.
Here is some SQL for your recordset which will work just fine provided your table isn't abnormally large.
When creating your Recordset, switch to Advanced view, and enter something like :-
SELECT picture,url FROM banners ORDER BY RAND()
This will create a recordset containing all of your banner information, but it will order them randomly so the first record will always be different, and therefore, whenever the page is refreshed and the recordset recreated you'll get a different banner.
Hope this helps...
(Oh and BTW, you can ask as many questions as you like, there are no quotas, and you're not being a pain <img src=../images/dmxzone/forum/icon_smile_wink.gif border=0 align=middle> )
Tim Green
tim@udzone.com
Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Here is some SQL for your recordset which will work just fine provided your table isn't abnormally large.
When creating your Recordset, switch to Advanced view, and enter something like :-
SELECT picture,url FROM banners ORDER BY RAND()
This will create a recordset containing all of your banner information, but it will order them randomly so the first record will always be different, and therefore, whenever the page is refreshed and the recordset recreated you'll get a different banner.
Hope this helps...
(Oh and BTW, you can ask as many questions as you like, there are no quotas, and you're not being a pain <img src=../images/dmxzone/forum/icon_smile_wink.gif border=0 align=middle> )
Tim Green
tim@udzone.com
Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Replied 23 years ago
23 years ago Owen Eastwick replied:
Random ordering is exactly what I need to do, so I tried:
SELECT * FROM TextTable ORDER BY RAND()
and got the following error message.
Microsoft JET Database Engine (0x80040E14)
Undefined function 'RAND' in expression.
I'm using an OLE DB connection rather that a DSN would that make a difference?
Any ideas?
Regards
Owen.
SELECT * FROM TextTable ORDER BY RAND()
and got the following error message.
Microsoft JET Database Engine (0x80040E14)
Undefined function 'RAND' in expression.
I'm using an OLE DB connection rather that a DSN would that make a difference?
Any ideas?
Regards
Owen.
Replied 23 years ago
23 years ago Tim Green replied:
Owen, the code I put up there was MySQL specific, and won't work on other DB's.
You would need to use something like this :-
SELECT *,rand() AS random_row FROM TextTable ORDER BY random_row
Tim Green
tim@udzone.com
Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Edited by - rawveg on 09/15/2001 01:44:55
You would need to use something like this :-
SELECT *,rand() AS random_row FROM TextTable ORDER BY random_row
Tim Green
tim@udzone.com
Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Edited by - rawveg on 09/15/2001 01:44:55
Replied 23 years ago
23 years ago Stephen Bateman replied:
You are a KING amongst men.
The MySQL tip works really well.
I owe you a drink big time!
Thanks Tim (rawveg)
The MySQL tip works really well.
I owe you a drink big time!
Thanks Tim (rawveg)
Replied 23 years ago
23 years ago Tim Green replied:
Stephen,
It is a pleasure, and whilst I give advice for free, I will hold you to that offer of a drink ! <img src=../images/dmxzone/forum/icon_smile_wink.gif border=0 align=middle>
Tim Green
tim@udzone.com
Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
It is a pleasure, and whilst I give advice for free, I will hold you to that offer of a drink ! <img src=../images/dmxzone/forum/icon_smile_wink.gif border=0 align=middle>
Tim Green
tim@udzone.com
Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Replied 20 years ago
20 years ago Dan Berdusco replied:
Hi,
Would you be able to tell me how I could do this using MS Access and ASP VB Script?
Thanks so much
Would you be able to tell me how I could do this using MS Access and ASP VB Script?
Thanks so much