Reply LinkBack Thread Tools Search this Thread
Old 21-09-2006, 10:29   #1 (permalink)
gray
i still want paying
 
gray's Avatar
 
Join Date: Oct 2003
Location: newcastle, uk
Posts: 4,713
mysql selecting random rows, but use priority levels

evening gents, im trying to get my sql to pull out a random row, but grab rows with a higher priority more often than lower priorty - but still show lower priority rows occasionally...

i was thinking this, but failed.

PHP Code:
// priority_level is a column with values 1-5, 5 being high priority
$getFile mysql_query("SELECT * FROM $table 
ORDER BY RAND(),priority_level DESC LIMIT 1"
); 

can it be done?
  Reply With Quote
Old 21-09-2006, 10:40   #2 (permalink)
gray
i still want paying
 
gray's Avatar
 
Join Date: Oct 2003
Location: newcastle, uk
Posts: 4,713
ah good one
  Reply With Quote
Old 21-09-2006, 10:42   #3 (permalink)
gray
i still want paying
 
gray's Avatar
 
Join Date: Oct 2003
Location: newcastle, uk
Posts: 4,713
i'll make an array of 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5 and select one at random
  Reply With Quote
Old 21-09-2006, 10:43   #4 (permalink)
gray
i still want paying
 
gray's Avatar
 
Join Date: Oct 2003
Location: newcastle, uk
Posts: 4,713
haha same idea

now some brain bod come along and say

"just use randomWithPriority() => foo ?: zx$" tbh
  Reply With Quote
Old 21-09-2006, 11:12   #5 (permalink)
gray
i still want paying
 
gray's Avatar
 
Join Date: Oct 2003
Location: newcastle, uk
Posts: 4,713
this will fail if there are no priority 4 rows for example.. going to have to check for existance of each level before adding that level to the array..
  Reply With Quote
Old 21-09-2006, 12:53   #6 (permalink)
gray
i still want paying
 
gray's Avatar
 
Join Date: Oct 2003
Location: newcastle, uk
Posts: 4,713
aye done it
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8