I dont know how to achieve this.
I have 2 tables in my database:
Table 1: rounds
+------------+----------+---------+----------+---------------+
| round_id | format | Size | poster | tournament_id |
+------------+----------+---------+----------+---------------+
| 6 | Single | 12 | Luis | 1
| 7 | Single | 9 | Daniel | 1 |
| 8 | Single | 4 | Oscar | 1 |
+------------+----------+---------+----------+---------------+
Table 2: matches
+------------+----------+-------------+----------+----------+
| round_id | player | position | score | winner |
+------------+----------+-------------+----------+----------+
| 6 | Doris | 0 | 1 | 1 |
| 7 | Arturo | 0 | 3 | 1 |
| 7 | Pablo | 1 | 2 | 0 |
| 8 | Ale | 0 | 1 | 0 |
| 8 | Maria | 1 | 5 | 1 |
| 8 | Roberto | 2 | 4 | 0 |
+------------+----------+-------------+----------+----------+
At the first table i have the rounds of the tournaments and at the second table the matches from each round, as you can see each match in a round can have different size of players. So i want to get all info of the rounds BUT just the last 2 rounds from the table "rounds", to get something like this in one query:
Result from query:
//The main key can be the round_id or numbers in order 0 to n //
[7] => Array
(
['poster'] => 'Daniel'
['format'] => 'single'
(
[0] => Array
(
['player'] => 'Arturo'
['score'] => 3
)
[1] => Array
(
['player'] => 'Pablo'
['score'] => 2
)
)
)
[8] => Array
(
['poster'] => 'Oscar'
['format'] => 'single'
(
[0] => Array
(
['player'] => 'Ale'
['score'] => 1
)
[1] => Array
(
['player'] => 'Maria'
['score'] => 5
)
[2] => Array
(
['player'] => 'Roberto'
['score'] => 4
)
)
)
So in my page i can show the last rounds uploaded, something like this:
+---------------------------+
| by Daniel |
| Arturo (3) vs Pablo (2) |
+---------------------------+
+---------------------------------------+
| by Oscar |
| Ale (1) vs Maria (5) vs Roberto (4) |
+---------------------------------------+
Hope a MySQL expert can help me with this :)