| Posted by Stefan Rybacki on 01/07/06 23:21 
-----BEGIN PGP SIGNED MESSAGE-----Hash: SHA1
 
 Joe wrote:
 > Hi
 > I need some help doing a easy php/sql solution to a random selection with
 > rated stuff.
 > I have a table like:
 >
 > Name Rated
 > --------------
 > Thompsen 500
 > Milla          10
 > Jensen         1
 >
 > Means that the name Thompsen appears 50 times as often as Milla and 500
 > times as often Jensen.
 >
 > I now need some scripting that counts the total ratefactor like
 > SELECT sum(Rated) FROM Table
 > In this case 511
 > And then make a random value between 1 and 511 and then print out the name,
 > which in this case will be Thompsen 500 of 511 times (in avg)
 >
 > I need a quick way to find a name based on the Rated factors, any help?
 >
 
 1. get your ratefactor (SELECT sum(rated) FROM table)
 2. create a random number between 1 and ratefactor in PHP
 3. get the random item (SELECT name FROM table WHERE rated>=created_randomnumber
 ORDER BY rated, rand() LIMIT 1)
 
 Regards
 Stefan
 
 
 
 
 
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.1rc2 (MingW32)
 
 iD8DBQFDwDDyyeCLzp/JKjARAq59AKCejex+Pq1JmUDNW36HYUH6GEzklACgxshu
 Q476HxNXNdZzwZAByq0pyNA=
 =LzSK
 -----END PGP SIGNATURE-----
  Navigation: [Reply to this message] |