Please help!
I have aMysql resultset where each row looks like:
(id,dow,time) where dow is NOT unique, so I might have:
1,1,7:00
2,1,8:00
3,2,7:00
3,2,8:00
I would like to end up with an array of arrays, where the outer array has keys = the dow value, so I want:
[
1 => [ 1,7:00 ] , [ 2,8:00 ] ,
2 => [ 3,7:00 ] , [ 4,8:00 ]
]
Here is what I have tried:
$days = array(); //outer array
while( $data = db_fetch_row($r) )
{
// $data holds dow, which I need to be key of outer array
$temp = array( $data[0],$data[1]) ;
if( ! is_array( $days[ $data[2] ] )
{
$days[ $data[2] ] = $temp;
}
else
{
array_push( $days[ $data[2] ], $temp);
}
}
Please help! I get weird results, some of the outer array is correct, while the other elements have strange values, and I don't know what is wrong. Here is sample output:
key: 1
5, 7
0, 7
64, 08:00:00
71, 09:00:00
key: 2
5, 8
0, 7
65, 08:00:00
72, 09:00:00
key: 3
5, 9
0, 7
66, 08:00:00
73, 09:00:00
key: 4
6, 0
0, 7
67, 08:00:00
74, 09:00:00
key: 5
6, 1
0, 7
68, 08:00:00
75, 09:00:00
key: 6
6, 2
0, 7
69, 08:00:00
76, 09:00:00
key: 7
6, 3
0, 7
70, 08:00:00
77, 09:00:00