Jump to content

Archived

This topic is now archived and is closed to further replies.

AlphaShade

Randomization by Table Integer

Recommended Posts

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 :)

Share this post


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

Share this post


Link to post
Share on other sites
[quote author=fenway link=topic=101835.msg403484#msg403484 date=1153866735]
Complex?  Sounds like you want to pull N random records from your table, and then sort by the popularity field.  What's the problem?
[/quote]

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.

Share this post


Link to post
Share on other sites
Assuming you're using 4.1+, you can accomplish this with a sub-query:

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

I didn't mean that you're question wasn't valid, just that the problem were you describing wasn't complex.

Share this post


Link to post
Share on other sites

×

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.