Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

League table form order

Featured Replies

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

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.

  • 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 = 4
LLWWL = 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?

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 :D

To find those winning most recently I think you need to do something a little more in the data.

Team Table
ID: 1
Name: Team One
Matches: 1,2,5,6

Match Table
ID: 1
Result: W
Date: TIMESTAMP

Then 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?

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.

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.