Forums
This topic is locked
Recordset in Random order ?
Posted 14 Sep 2001 03:13:35
1
has voted
14 Sep 2001 03:13:35 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 14 Sep 2001 14:20:03
14 Sep 2001 14:20:03 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
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
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 14 Sep 2001 14:27:22
14 Sep 2001 14:27:22 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 15 Sep 2001 00:00:07
15 Sep 2001 00:00:07 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
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
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 15 Sep 2001 00:30:08
15 Sep 2001 00:30:08 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 15 Sep 2001 01:43:14
15 Sep 2001 01:43:14 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
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
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 15 Sep 2001 02:14:27
15 Sep 2001 02:14:27 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 17 Sep 2001 11:49:44
17 Sep 2001 11:49:44 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
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
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 21 Jun 2004 19:33:23
21 Jun 2004 19:33:23 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