Jump to content


Photo

Randomization by Table Integer


  • Please log in to reply
4 replies to this topic

#1 AlphaShade

AlphaShade
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 25 July 2006 - 07:52 PM

Hello!

Well basically I have a problem.

I have a table with a value: Popularity. What I want to do is do a site randomization.

I have rows: id, url, website_description, popularity

What I want to do is do a randomization where a site will come up in the script by a popularity number of 1 to 100(or more).

My problem is I have seen plenty of randomization scripts out there but nothing this complex.

Wondering if someone knows a way to do this. I want it to randomize all sites but those sites that have the highest popularity rating would show up more then the sites with the lowest.

Any help you can give me would be great!
Thanks for reading :)

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 25 July 2006 - 10:32 PM

Complex?  Sounds like you want to pull N random records from your table, and then sort by the popularity field.  What's the problem?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 AlphaShade

AlphaShade
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 26 July 2006 - 12:17 PM

Complex?  Sounds like you want to pull N random records from your table, and then sort by the popularity field.  What's the problem?


Complex to me because I do not know how to do that. And problem is I am such a newbie that I do not know how I would do it. Thus my reason for asking if someone knew.

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 26 July 2006 - 03:34 PM

Assuming you're using 4.1+, you can accomplish this with a sub-query:

SELECT id, url, website_description, popularity FROM yourTable WHERE id IN ( SELECT id FROM yourTable ORDER BY RAND() LIMIT 5 ) ORDER BY popularity DESC

I didn't mean that you're question wasn't valid, just that the problem were you describing wasn't complex.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 AlphaShade

AlphaShade
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 26 July 2006 - 06:07 PM

Thanks, Oh I didnt understand what you meant by whats the problem :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users