Jump to content

Sort, and randomize similar values... need help


kaputski

Recommended Posts

Ok guys I tried using Rand() and it did not work... I also tried to use these other alternatives to Rand() but still no go.. what i'm trying to acheive is sorting my table and some of the results are the same... and i'd like those results randomized in order.  The table is for fans who donate to my site, and i'm limiting the number of users displayed on page to 10 so i need the like values to be random so each time the users names will switch out.  Here's basically what i'm talking about.  Table is set up like this:

 

superfan (table name)

| displayname | email | donation |

| fan1 | fan@email.com | 15 |

| fan2 | fan@email.com | 15 |

| fan3 | fan@email.com | 10 |

| fan4 | fan@email.com | 5 |

| fan5 | fan@email.com | 5 |

| fan6 | fan@email.com | 5 |

 

Now lets say i wanted to just limit this to 5 results... i would want the two 15 amounts listed first, then the fan with 10, finally the remaining 2 would show 5... Now i need each each 15 value fans to swich places randomly... the 10 should stay the same spot because there is no other 10... and the 5's should rotate positions randomly so each user will have times where their name is displayed.  So basically i need 'donation' sorted first.. highest to lowest, then all like amounts randomly displayed.

 

Here's the code I tried with rand() that didnt work...

 

$query  = "SELECT * FROM superfan ORDER BY donation DESC, RAND() LIMIT 15";

 

Any suggestions?  And try to keep it simple or with a good explanation what's going on lol.. I can't do advanced mysql too well

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.