I have the following table,
id | booki_id | bet_id | bet | bettype | line | odds
1 | 123 | 321 | 1 | 3way | 0,0 | 2.3
2 | 123 | 321 | 2 | 3way | 0,0 | 3.4
3 | 123 | 322 | 1 | 3way | 0,0 | 1.1
4 | 123 | 322 | 2 | 3way | 0,0 | 7.4
5 | 123 | 323 | 1 | 3way | 0,0 | 1.3
6 | 123 | 323 | 2 | 3way | 0,0 | 9.4
How can I get the following array? Or can I get wit one selection?
array
(
[0]=>array
(
"booki_id"=>123,
"betid"=>321,
"bet"=>array([1]=>2.3
[2]=>3.4
),
"bettype"=>"3way",
"line"=>0
),
[1]=>array
(
"booki_id"=>123,
"betid"=>323,
"bet"=>array([1]=>1.3
[2]=>9.4
),
"bettype"=>"3way",
"line"=>0
)
[2]=>array
(
"booki_id"=>123,
"betid"=>322,
"bet"=>array([1]=>1.1
[2]=>7.4
),
"bettype"=>"3way",
"line"=>0
)
)
And It's ordered by bet[1];
UPDATED:
id | booki_id | bet_id | bet | bettype | line | odds
1 | 123 | 321 | 1 | 3way | 0,0 | 2.3
2 | 123 | 321 | 2 | 3way | 0,0 | 3.4
3 | 123 | 321 | x | 3way | 0,0 | 2.4
4 | 123 | 322 | 1 | 3way | 0,0 | 1.1
5 | 123 | 322 | 2 | 3way | 0,0 | 7.4
6 | 123 | 322 | x | 3way | 0,0 | 3.4
7 | 123 | 323 | 1 | 3way | 0,0 | 1.3
8 | 123 | 323 | 2 | 3way | 0,0 | 9.4
9 | 123 | 323 | x | 3way | 0,0 | 6.4
And sometimes I have to order by bet[2] or bet[x];
Best Answer
I tried to produce the same ordering and having some trouble but here are two different queries you can start with:
I also created sample data to test it with, and here it is:
You will have to play with the order of the whole rows from here.
Give it a Try !!!