Jump to content

Randomization by Table Integer


AlphaShade

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 :)
Link to comment
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.
Link to comment
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.
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.