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

   Getting a random Post... to Del.icio.us Add to del.icio.us
  Digg Getting a random Post... Digg it
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
1 Registered (Gizmo), 26 Guests and 11 Spiders online.
Key: Admin, Global Mod, Mod
Shout Box

Latest Posts
Team UBBDev Rides Again!
by AllenAyres
10/13/08 01:36 PM
Blogs, love em or hate em?
by AllenAyres
10/07/08 02:05 PM
What do you use to edit the files
by Ian_W
10/05/08 03:33 PM
BeyondCompare v3.00
by Ian_W
10/05/08 03:32 PM
Glossy Black Theme with Image Reflection
by Gizmo
10/05/08 02:17 PM
ShareThis
by Gizmo
09/28/08 05:06 AM
[7.3] Viewing MySQL logfiles made easier
by AllenAyres
09/27/08 09:57 PM
New Mods
[7.3] Viewing MySQL logfiles made easier
by blaaskaak
09/24/08 05:39 PM
[7.3.1] add search to showmembers page
by blaaskaak
09/07/08 04:50 AM
Newest Members
Kevs, pisa666, ghengis317, NitroX, Dogan
13346 Registered Users
Top Posters Last 30 Days
AllenAyres 11
blaaskaak 6
Ian_W 4
tackaberry 4
Chris Bale 4
Gizmo 4
FREAK1 4

 

 

 
fusionbb message board php hacks