devilinc Posted April 30, 2010 Share Posted April 30, 2010 ::)I have a switch statement to calculate the player's analysis like their skill speed etc.... This is not the best way to do this because switch statement will get very long. Please recommend a better way to do this. Quote Link to comment https://forums.phpfreaks.com/topic/200264-cakephp-switching/ Share on other sites More sharing options...
devilinc Posted April 30, 2010 Author Share Posted April 30, 2010 a lil more detail...taken from database table... if player selected display his position and attributes. using switch statement to perform certain tasks like getting his position and his team... Quote Link to comment https://forums.phpfreaks.com/topic/200264-cakephp-switching/#findComment-1050966 Share on other sites More sharing options...
trq Posted April 30, 2010 Share Posted April 30, 2010 Without seeing some code, we can't really be of much assistance. Quote Link to comment https://forums.phpfreaks.com/topic/200264-cakephp-switching/#findComment-1050979 Share on other sites More sharing options...
devilinc Posted April 30, 2010 Author Share Posted April 30, 2010 just wanted to know a beter way than switch....guess its programming logic i am asking here....anyone out there??? Quote Link to comment https://forums.phpfreaks.com/topic/200264-cakephp-switching/#findComment-1050987 Share on other sites More sharing options...
trq Posted April 30, 2010 Share Posted April 30, 2010 Without seeing your code we can't really help. Maybe you could use a loop to execute a series of tests? Without code, we are just guessing as to what your code actually does. Quote Link to comment https://forums.phpfreaks.com/topic/200264-cakephp-switching/#findComment-1050988 Share on other sites More sharing options...
devilinc Posted April 30, 2010 Author Share Posted April 30, 2010 thot tht...neways thnx for helping out.... Quote Link to comment https://forums.phpfreaks.com/topic/200264-cakephp-switching/#findComment-1050990 Share on other sites More sharing options...
Adam Posted April 30, 2010 Share Posted April 30, 2010 ... clever guy. Quote Link to comment https://forums.phpfreaks.com/topic/200264-cakephp-switching/#findComment-1050994 Share on other sites More sharing options...
devilinc Posted May 3, 2010 Author Share Posted May 3, 2010 hehehe...if its not switch then its loops rt??? lol... Quote Link to comment https://forums.phpfreaks.com/topic/200264-cakephp-switching/#findComment-1052216 Share on other sites More sharing options...
devilinc Posted June 8, 2010 Author Share Posted June 8, 2010 a little more detail.... here is my situation in detail... i retrieve a "value" from database...and call a function named $this->value('some id again from database'); the "value" here is the name of the function i wish to call....i manually entered those function names into the db and if a condition is satisfied tht function gets called..... an example of value could be _getProcessedPlyr or _getReadPlyr or _getWritePlyr.......is it possible or not? as the value changes the function called should be different.... if anyone has some better suggestion to implement this please feel free to comment.... well, my db has class functions names cos i need to use those corresponding functions, only if certain condition is met....again this condition is stored ion the db too....condition means like if it is a do this function and if b do this other function.... hope you got a clearer picture now...so i would like to process this in a beter way..... Quote Link to comment https://forums.phpfreaks.com/topic/200264-cakephp-switching/#findComment-1069287 Share on other sites More sharing options...
trq Posted June 8, 2010 Share Posted June 8, 2010 Assuming your database data is within $row['value']. $this->${$row['value']}(); Why your storing logic within your db is beyond me. Quote Link to comment https://forums.phpfreaks.com/topic/200264-cakephp-switching/#findComment-1069301 Share on other sites More sharing options...
devilinc Posted June 8, 2010 Author Share Posted June 8, 2010 there is no logic....its just markers..... Quote Link to comment https://forums.phpfreaks.com/topic/200264-cakephp-switching/#findComment-1069307 Share on other sites More sharing options...
devilinc Posted June 8, 2010 Author Share Posted June 8, 2010 i mean to say there is no logic in db....its just like say markers a,b,c etc..... Quote Link to comment https://forums.phpfreaks.com/topic/200264-cakephp-switching/#findComment-1069389 Share on other sites More sharing options...
devilinc Posted June 29, 2010 Author Share Posted June 29, 2010 :facewall:Please I badly need help!!! Let's make this simpler as to why I should avoid switch/case statement. Switch/case is used as such... a list of fatas(i.e. player stats and external stats like weather) and a list of players are selected by user. now we have to calculate for each player his grade or say percentage based on the fatas selected Fatas are stored in db, with their id's and selected fatas are stored in a table with foreign keys. Now, the switch is used based on the fata id. so i give a code sample here which would help you people to help me out. Inside analyze function i do the switching for each fata. switch ($f['Fata']['id']) { //Rushing - Yds - Total (2009) case 14: $results[$p['Plyr']['id']][$f['Fata']['id']] = $this->_getFataRushYdTot($p['Plyr']['id']); if ($results[$p['Plyr']['id']][$f['Fata']['id']] == '') { $results[$p['Plyr']['id']][$f['Fata']['id']] = 'Info Not Available'; } else { $results[$p['Plyr']['id']][$f['Fata']['id']] = $results[$p['Plyr']['id']][$f['Fata']['id']].' yds'; } break; } //calculate fata function _getFataRushYdTot($id=null) { if ($id) { //get the user's team $this->Plyr->recursive = 0; $p = $this->Plyr->findById($id); // get XML file $parsed_xml = $this->_parseXml(WWW_ROOT.'xml_data/NFLRushingLeadersXML-RUSHERS.xml'); //get the info from XML $data = ''; foreach ($parsed_xml['Message']['Listing'] as $p_xml) { if (strncasecmp($p_xml['name'], $p['Plyr']['first_name'].' '.$p['Plyr']['last_name'].', '.$p['SportTm']['location_abbrev'], strlen($p_xml['name'])) == 0) { $data = $p_xml['yards']; break; } } return ($data); } } so, here is my problem now. i want to remove these switch/case cos currently i have just 100 fatas, but i plan to include about a 1000 fatas. u don't expect me to write a function and also a case for each fata added. anybody wid suggestions??? Quote Link to comment https://forums.phpfreaks.com/topic/200264-cakephp-switching/#findComment-1078613 Share on other sites More sharing options...
devilinc Posted June 29, 2010 Author Share Posted June 29, 2010 //calculate fata function _getFataInj($id=null) { if ($id) { //get the user's team $this->Plyr->recursive = 0; $p = $this->Plyr->findById($id); // get XML file $parsed_xml = $this->_parseXml(WWW_ROOT.'xml_data/Injuries_Detail_XML.xml'); // XML Path // Sports-content-set... Sports-content... Statistic... Team... []... // Team-metadata... Name... // team --> "first" or "last" // Player... []... // Player-metadata... // Plyr -> Name... full // Injury (body part) --> Injury-phase... injury-type // Injury (type) --> Injury-phase... phase-type // Injury (details) --> Injury-phase... xts:tsn-phase-type $data = ''; foreach ($parsed_xml['Sports-content-set']['Sports-content']['Statistic']['Team'] as $key => $tm) { // if ($key != 0) { if ($tm['Team-metadata']['Name']['last'] == $p['SportTm']['mascot_name']) { foreach ($tm['Player'] as $p_xml) { if ($p_xml['Player-metadata']['Name']['full'] == ($p['Plyr']['first_name'].' '.$p['Plyr']['last_name'])) { $data = $p_xml['Player-metadata']['Injury-phase']['phase-type'].' ('.$p_xml['Player-metadata']['Injury-phase']['injury-type'].') - '.$p_xml['Player-metadata']['Injury-phase']['xts:tsn-phase-type']; break; } } break; } // } } //return injury status return($data); } } Quote Link to comment https://forums.phpfreaks.com/topic/200264-cakephp-switching/#findComment-1078625 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.