February 27, 201412 yr Hi everyone, I was wondering if anyone could help me with this problem. I've been scratching my head for a while with this one. So in sport you'll have a teams current form of Win Loss Draw Draw Win (WLDDW) for example. What I'm trying to do is order my results from the database by those who currently have the best form. So my results would be in order of form Team D - WWWLL Team E - LWDLL Team B - LDWLL Team C - WLLLL Team A - LLLLD Does anyone have any ideas? Many thanks
March 5, 201412 yr How have you saved your data? Is it with a W and D?If you made the data save as 0 for a loss and 1 for a win then you could count it and then order by the highest value.
March 5, 201412 yr Author Thanks for your reply EpicWebs The data is currenly saved as W, D, L. But if we take your way of totaling up the value, which is correct for initially sorting the form, we may have the following situation WWLLL = 2+2+0+0+0 = 4 LLLWW = 0+0+0+2+2 = 4LLWWL = 0+0+2+2+0 = 4 The total would not give us any particular order, though the order of form should be WWLLL LLWWL LLLWW With those winning most recently coming out on top. any ideas?
March 6, 201412 yr Hmm sorting by letter Desc won't cut it. What about assigning W = a, D = b and L = c and sort by letter then put them back on the output? Something like; function convert_results($string) { $find = array("W", "D", "L"); $replace = array("a", "b", "c"); $outcome = str_replace($find, $replace, $string); return $outcome; } $result = "WWWLL"; $result-sort = convert_results($result); If you then create a multidimensional array with team name, $result and $result_sort. You can then sort by $result_sort asc as "WWWLL" will become "aaacc" and "LLDWW" would be "ccbaa"? Just an idea
March 6, 201412 yr To find those winning most recently I think you need to do something a little more in the data.Team TableID: 1Name: Team OneMatches: 1,2,5,6Match TableID: 1Result: WDate: TIMESTAMPThen when you pull the team data you can also pull the matches from the match ids.Once you have that then you can sort teams initially by the most wins and then by the team who has won the most recently.The thing to think about is, will a team with more wins come higher and then the most recent comes after? Or the other way around?
March 6, 201412 yr To find those winning most recently I think you need to do something a little more in the data. Yes, that was my thought but it's down to what data has already been stored. 2 tables is the best method as then you could expand each so the matches could add weather conditions, who scored etc and the 'team' information like players etc but it depends on the project wider picture.
March 10, 201412 yr Yea, it might just not be worth while re-doing the database structure, it all depends on the goal of the project as a whole.
Create an account or sign in to comment