leeandrew Posted March 10, 2008 Share Posted March 10, 2008 I have made a rating script like hot or not. The top images are displayed in a toplist; i can have multiple toplists for different categories of pictures. I'm trying to find a way to have one big league system instead of different toplists for different categories. Example: I'd like to set up 3 leagues. People rate the pictures and each week the top 3 pictures from league 3 move into league 2, while the bottom 3 pictures from league 2 are demoted to league 3 and so on. Each week the votes are reset and voting continues as usual for another week etc. I'm having trouble thinking where to start coding. Any suggestions of scripts that do similar jobs? Link to comment https://forums.phpfreaks.com/topic/95467-ladderleague-system-coding/ Share on other sites More sharing options...
Barand Posted March 10, 2008 Share Posted March 10, 2008 Below is one way of promoting/demoting. Of course you'll need a way to allocate scores and preserving the results while scores are collected for the next week. You may want to lookup the functions used www.php.net/arsort www.php.net/array_slice www.php.net/array_merge <?php /** * code to create 3 leagues of * 8 members with random scores * and save me typing in data */ $member = 'A'; $ladder = array(); for ($i=0; $i < 24; $i++) { $league = $i%3; $score = rand(1,50); $ladder[$league][$member] = $score; $member++; } /** * sort each league by rating desc */ for ($leag=0; $leag<3; $leag++) { arsort ($ladder[$leag]); } /** * show ladder */ echo '<pre>', print_r($ladder, true), '</pre>'; /** * now promote/demote teams */ promote ($ladder, 0, 1); // leagues 0 and 1 promote ($ladder, 1, 2); // leagues 1 and 2 /** * show new ladder */ echo '<pre>', print_r($ladder, true), '</pre>'; /** * function to promote/demote between two leagues */ function promote (&$ladder, $a, $b) { $ka = count($ladder[$a]); $topa = array_slice ($ladder[$a], 0, $ka-3); $bota = array_slice ($ladder[$a], $ka-3); // lower 3 from league a $topb = array_slice ($ladder[$b], 0, 3); // top 3 from league b $botb = array_slice ($ladder[$b], 3); $ladder[$a] = array_merge($topa, $topb); // promote $ladder[$b] = array_merge($bota, $botb); // demote } ?> Link to comment https://forums.phpfreaks.com/topic/95467-ladderleague-system-coding/#findComment-488830 Share on other sites More sharing options...
leeandrew Posted March 10, 2008 Author Share Posted March 10, 2008 Thanks for your reply, i will read up on those functions and fiddle around with the code you gave me. I'll post any results. Link to comment https://forums.phpfreaks.com/topic/95467-ladderleague-system-coding/#findComment-488969 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.