Results 1 to 3 of 3

Thread: Making A Rank System In PHP

  1. #1
    Registered Mike's Avatar
    Join Date
    May 2003
    Location
    UK
    Posts
    2,755

    Making A Rank System In PHP

    Hi all.

    I'm currently doing a project which involves giving "weight" to a row in a database. Basically, the more weight the row has, the more times it will be picked.

    The problem, I don't know how to do what I've just said. First I was thinking about using rand(), but then realised it wouldn't really work with that.

    I have run out of ideas, anyone know what I could do?

    Cheers,
    Mike
    Don't you just love free internet games ?

  2. #2
    Chronic Entrepreneur
    Join Date
    Nov 2003
    Location
    Tulsa, Oklahoma, USA
    Posts
    1,112
    Try this (untested) :

    Code:
    SELECT * FROM Table ORDER BY RAND()*(1/weight) LIMIT 1;
    This assumes that each row has an integer field called 'weight'. The higher the number in this field the more likely it is for the row to be selected.

  3. #3
    Registered Mike's Avatar
    Join Date
    May 2003
    Location
    UK
    Posts
    2,755
    Yup, that's it - I never knew you could use queries like that. Thanks Westech
    Don't you just love free internet games ?

Similar Threads

  1. Is any other method to get Website PR ?
    By number7 in forum Search Engine Optimization
    Replies: 10
    Last Post: 01-08-2019, 03:33 AM
  2. Review: Professional PHP Programming
    By Chris in forum Books
    Replies: 6
    Last Post: 07-17-2013, 05:26 AM
  3. Replies: 0
    Last Post: 02-27-2005, 10:43 PM
  4. Replies: 2
    Last Post: 02-20-2005, 11:30 PM
  5. PHP making my page views smaller
    By incka in forum General Chat
    Replies: 8
    Last Post: 12-22-2003, 05:34 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •