php forum
php mysql forum
php mysql smarty
 
Topic Options
#234675 - 01/30/03 01:28 PM Getting a random Post...
PhotoPost Offline
Hacker

Registered: 02/03/02
Posts: 989
We're running a contest on our board. Each person who votes during the month will get one entry. Then we want to run a query to get a random post that is between the two dates (whole month); giving each person who posted one shot at winning.<br /><br />Anyone have a suggestion on a query that could do this - or do I need to write a script?
_________________________
[]http://www.danasoft.com/vipersig.jpg[/]
Viper Alley - http://www.viperalley.com
Extreme Fitness - http://www.extremefitness.com[/b]

Top
#234676 - 01/31/03 08:28 AM Re: Getting a random Post... [Re: gailg]
Astaran Offline
Addict

Registered: 12/21/00
Posts: 1545
Loc: Germany
MySQL has an mathemetical function to generate a random number with a value between 0.0 and 1.0 but this won't help you much, i suppose.<br /><br />You could also try something like this, which works good on small tables:<br /><br />SELECT * FROM tablename where B_Posted > '$startdate' and B_Posted < '$enddate' ORDER BY RAND() LIMIT 1<br /><br />This is not a good idea if your posts table has moore than about 300.000 entries.<br /><br />Since the startdate and enddate changes each month, you need to write a script anyway.<br />So generating a random number could be done with php also.<br />Something like this should work:<br /><br />SELECT MIN(B_Number), MAX(B_Number) where B_Posted > '$startdate' and B_Posted < '$enddate' FROM tablename;<br /><br />Fetch the result into $a<br /><br />$id=rand($a[0],$a[1]);<br /><br />SELECT * FROM tablename WHERE B_Number>='$d' LIMIT 1
_________________________
Running a community? -> Keep informed and take it to the next level

Top


Who's Online
0 registered (), 24 Guests and 9 Spiders online.
Key: Admin, Global Mod, Mod
Shout Box

Latest Posts
Spell Check [beta]
by Bill B
48 minutes 24 seconds ago
PhotoPost BB Code Popup
by AllenAyres
Today at 09:41 AM
Problems reading a lot of old posts here
by AllenAyres
Today at 09:35 AM
Forum 'Trader Ratings'.
by AllenAyres
Today at 09:33 AM
Customization needed
by Gizmo
11/12/08 12:28 PM
Team UBBDev Rides Again!
by AllenAyres
11/11/08 02:16 PM
Active Topics.
by AllenAyres
11/11/08 02:13 PM
New Mods
User Authentication Class
by
01/19/07 02:59 PM
Multiple Identity Detector
by
12/30/06 06:39 PM
PhotoPost BB Code Popup
by
11/06/06 05:43 PM
Spell Check [beta]
by
10/17/06 09:24 PM
Newest Members
David DelMonte, nick1, Begbie, cenk, MATTO
13363 Registered Users
Top Posters
AllenAyres 25452
JoshPet 11330
Rick 8372
LK 7396
Lord Dexter 6503
Greg Hard 5533
Charles Capps 5438

 

 

 
fusionbb message board php hacks