rishibala143 Posted December 4, 2009 Share Posted December 4, 2009 Hi I need to display the probability for the given number. Suppose if the given number is 2. It should display (W - Win and L - Loss) W - W W - L L - W L - L It should generate the probability dynamically for the given number.I dont know how to do this using php.. Please help...Its Urgent... Thanks & Regards P.Balakrishnan Quote Link to comment https://forums.phpfreaks.com/topic/183950-urgent-need-php-code-to-display-the-probability-for-the-given-number/ Share on other sites More sharing options...
rishibala143 Posted December 4, 2009 Author Share Posted December 4, 2009 Hi I need to generate probability for win and loss in round...If there are 2 rounds the probability will be W-W W-L L-W L-L and if there are three rounds i want to generate the probability dyanamically..I need this for the below query SELECT team_id, GROUP_CONCAT( play_result, round_no ORDER BY round_no SEPARATOR '-' ) AS team_res, SUM( play_total ) AS total FROM tbl_play GROUP BY team_id HAVING team_res = 'W1-W2' || team_res = 'W1-L2' || team_res = 'L1-W2' || team_res = 'L1-L2' ORDER BY total DESC In this above query the win and loss is hardcoded for two rounds...If there is 3 round i have to write like this SELECT team_id, GROUP_CONCAT( play_result, round_no ORDER BY round_no SEPARATOR '-' ) AS team_res, SUM( play_total ) AS total FROM tbl_play GROUP BY team_id HAVING team_res = 'W1-W2-W3' || team_res = 'W1-W2-L3' || team_res = 'W1-L2-W3' etc... So only i need to generate the probability of given number(i.e round number.) Please help Quote Link to comment https://forums.phpfreaks.com/topic/183950-urgent-need-php-code-to-display-the-probability-for-the-given-number/#findComment-971045 Share on other sites More sharing options...
JustLikeIcarus Posted December 4, 2009 Share Posted December 4, 2009 You can possibly try a cartesian join of the table on its self. Google "cartesian join" and see if that leads anywhere. Quote Link to comment https://forums.phpfreaks.com/topic/183950-urgent-need-php-code-to-display-the-probability-for-the-given-number/#findComment-971301 Share on other sites More sharing options...
MadTechie Posted December 4, 2009 Share Posted December 4, 2009 Wrong section for Urgent and wrong section for requesting code Quote Link to comment https://forums.phpfreaks.com/topic/183950-urgent-need-php-code-to-display-the-probability-for-the-given-number/#findComment-971334 Share on other sites More sharing options...
rishibala143 Posted December 5, 2009 Author Share Posted December 5, 2009 Hi I got the solution...Thank u for ur support... Code: --------- <? print_r(probableOutcomes(4)); function probableOutcomes($num) { $resultArray = array(); for ($i = 0; $i < $num; $i++) { $binaryString .= "1"; } for ($i = 0; $i <= bindec($binaryString); $i++) { $resultString = str_pad(decbin($i), $num, "0", STR_PAD_LEFT); $resultString = str_replace("0", "W", $resultString); $resultString = str_replace("1", "L", $resultString); array_push($resultArray, $resultString); } return $resultArray; } ?> --------- The above example outputs Code: --------- Array ( [0] => WWWW [1] => WWWL [2] => WWLW [3] => WWLL [4] => WLWW [5] => WLWL [6] => WLLW [7] => WLLL [8] => LWWW [9] => LWWL [10] => LWLW [11] => LWLL [12] => LLWW [13] => LLWL [14] => LLLW [15] => LLLL ) This works for me.. Regards P.Balakrishnan Quote Link to comment https://forums.phpfreaks.com/topic/183950-urgent-need-php-code-to-display-the-probability-for-the-given-number/#findComment-971723 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.