[clue-tech] PHP/MySQL question

Matt Gushee matt at gushee.net
Thu Sep 22 20:28:24 MDT 2005


Hi yall.

I am currently rebuilding my Web site using PHP & MySQL, and I have a 
quick question for the gurus:

I want to create a link menu with a weighted random sort--i.e. the 
specific order is randomized each time, but based on a 'coolness factor' 
that I assign, certain sites will appear near the top more often than 
others. Now, it looks like I can do the sort either in PHP or in SQL. If 
I do it in SQL, the query would be something like this:

   SELECT title, url, description FROM links
       WHERE rg > 0
       ORDER BY RAND() * rg DESC
       LIMIT 35;

rg is the 'coolness factor'; it is a TINYINT field with possible values 
from 0-5 (0 means disabled). 35 (or so) rows is an arbitrary limit, just 
  to keep the menu down to a reasonable size; I expect there will be 
around 100-300 records in the table at any given time.

On the face of it, the above query seems like the best solution. Is 
there any reason to think it would be a bad idea, or that doing the 
sort-and-limit in PHP would be better?

--
Matt Gushee
Englewood, CO, USA
_______________________________________________
CLUE-tech mailing list
CLUE-tech at cluedenver.org
http://cluedenver.org/mailman/listinfo/clue-tech



More information about the clue-tech mailing list