Hi, i don't know how to do the following or even if it's possible.

These are 3 tables from my database sport:
[team]-|-----<-[team_match]->-----|-[match]

  • Team:
    • id (int)
    • name (text)
  • Team_match:
    • match_id (bigint)
    • team_id (int)
    • score (text) {this is not an integer because it can contain "f" for "forfait"}
    • home (tinyint) {this is a boolean, which indicates if the team plays at home for this match}
  • Match
    • id (bigint)
    • time (datetime)

With this setup, a match contains two entries of Team_match.
What i want to do in PHP is creating a two-dimensional array of matches, ordered alphabetically by the team's name.

To give you an example:
3 teams: Allstars, Bulls, Children
[Allstars vs. Bulls] [Allstars vs. Children]
[Bulls vs. Allstars] [Bulls vs. Children]
[Children vs. Allstars] [Children vs.Bulls]

How can i order the data first alphabetically by the team playing home, and then by the visitors?

Thanks in advance,
greets, Kenny.

From the example you wrote, there isn't an order by home

Can you post an example that shows what you want?

Oh, i think my description was wrong. I meant that there should be 2 levels of sorting (maybe more, but these 2 levels are the problem).

Example: [Allstars vs. Bulls] contains
Team_match:
* match_id: 1
* team_id: 1
* score: 10
* home: 1 (true)
These are the "Allstars"
Team_match:
* match_id: 1
* team_id: 2
* score: 12
* home: 0 (false)
These are the "Bulls"

Then the sorting:
[Allstars vs. Bulls] [Allstars vs. Children]
[Bulls vs. Allstars] [Bulls vs. Children]
[Children vs. Allstars] [Children vs.Bulls]

In the first dimension of the array the teams playing home should be sorted alphabetically:
[Allstars vs. Bulls]
[Bulls vs. Allstars]
[Children vs. Allstars]

In the second dimension of the array the visitors should be sorted alphabetically:
[Allstars vs. Bulls] [Allstars vs. Children]

But i think i found the solution :). But i'm still doing some testing.

Greets, K?!.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.