Yii: группировка по датам
Задача следущая, нужно вывести статьи по датам например:
/** * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann * (http://qbnz.com/highlighter/ and http://geshi.org/) */ .php.geshi_code {font-family:monospace;} .php.geshi_code .imp {font-weight: bold; color: red;} .php.geshi_code .kw1 {color: #b1b100;} .php.geshi_code .kw2 {color: #000000; font-weight: bold;} .php.geshi_code .kw3 {color: #990000;} .php.geshi_code .co1 {color: #666666; font-style: italic;} .php.geshi_code .co2 {color: #666666; font-style: italic;} .php.geshi_code .co3 {color: #0000cc; font-style: italic;} .php.geshi_code .co4 {color: #009933; font-style: italic;} .php.geshi_code .coMULTI {color: #666666; font-style: italic;} .php.geshi_code .es0 {color: #000099; font-weight: bold;} .php.geshi_code .es1 {color: #000099; font-weight: bold;} .php.geshi_code .es2 {color: #660099; font-weight: bold;} .php.geshi_code .es3 {color: #660099; font-weight: bold;} .php.geshi_code .es4 {color: #006699; font-weight: bold;} .php.geshi_code .es5 {color: #006699; font-weight: bold; font-style: italic;} .php.geshi_code .es6 {color: #009933; font-weight: bold;} .php.geshi_code .es_h {color: #000099; font-weight: bold;} .php.geshi_code .br0 {color: #009900;} .php.geshi_code .sy0 {color: #339933;} .php.geshi_code .sy1 {color: #000000; font-weight: bold;} .php.geshi_code .st0 {color: #0000ff;} .php.geshi_code .st_h {color: #0000ff;} .php.geshi_code .nu0 {color: #cc66cc;} .php.geshi_code .nu8 {color: #208080;} .php.geshi_code .nu12 {color: #208080;} .php.geshi_code .nu19 {color:#800080;} .php.geshi_code .me1 {color: #004000;} .php.geshi_code .me2 {color: #004000;} .php.geshi_code .re0 {color: #000088;} .php.geshi_code span.xtra { display:block; }
Array
(
[2000/10/10] => Array
(
[1] => Array
(
[name] = Post 1
[time] = 12:10
)
[2] => Array
(
[name] = Post 2
[time] = 16:20
)
[3] => Array
(
[name] = Post 3
[time] = 20:30
)
)
[2000/10/11] => Array
(
[6] => Array
(
[name] = Post 6
[time] = 10:00
)
)
)
Спасибо.
/** * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann * (http://qbnz.com/highlighter/ and http://geshi.org/) */ .php.geshi_code {font-family:monospace;} .php.geshi_code .imp {font-weight: bold; color: red;} .php.geshi_code .kw1 {color: #b1b100;} .php.geshi_code .kw2 {color: #000000; font-weight: bold;} .php.geshi_code .kw3 {color: #990000;} .php.geshi_code .co1 {color: #666666; font-style: italic;} .php.geshi_code .co2 {color: #666666; font-style: italic;} .php.geshi_code .co3 {color: #0000cc; font-style: italic;} .php.geshi_code .co4 {color: #009933; font-style: italic;} .php.geshi_code .coMULTI {color: #666666; font-style: italic;} .php.geshi_code .es0 {color: #000099; font-weight: bold;} .php.geshi_code .es1 {color: #000099; font-weight: bold;} .php.geshi_code .es2 {color: #660099; font-weight: bold;} .php.geshi_code .es3 {color: #660099; font-weight: bold;} .php.geshi_code .es4 {color: #006699; font-weight: bold;} .php.geshi_code .es5 {color: #006699; font-weight: bold; font-style: italic;} .php.geshi_code .es6 {color: #009933; font-weight: bold;} .php.geshi_code .es_h {color: #000099; font-weight: bold;} .php.geshi_code .br0 {color: #009900;} .php.geshi_code .sy0 {color: #339933;} .php.geshi_code .sy1 {color: #000000; font-weight: bold;} .php.geshi_code .st0 {color: #0000ff;} .php.geshi_code .st_h {color: #0000ff;} .php.geshi_code .nu0 {color: #cc66cc;} .php.geshi_code .nu8 {color: #208080;} .php.geshi_code .nu12 {color: #208080;} .php.geshi_code .nu19 {color:#800080;} .php.geshi_code .me1 {color: #004000;} .php.geshi_code .me2 {color: #004000;} .php.geshi_code .re0 {color: #000088;} .php.geshi_code span.xtra { display:block; }
Array
(
[2000/10/10] => Array
(
[1] => Array
(
[name] = Post 1
[time] = 12:10
)
[2] => Array
(
[name] = Post 2
[time] = 16:20
)
[3] => Array
(
[name] = Post 3
[time] = 20:30
)
)
[2000/10/11] => Array
(
[6] => Array
(
[name] = Post 6
[time] = 10:00
)
)
)
Спасибо.
1 ответов
Побольше бы исходных данных задачи...
Вот смотри как можно интерпретировать:
$input = Array(
6 => Array(
'name' => 'Post 6',
'time' => '2000/10/11 10:00',
),
1 => Array(
'name' => 'Post 1',
'time' => '2000/10/10 12:10',
),
2 => Array(
'name' => 'Post 2',
'time' => '2000/10/10 16:20',
),
3 => Array(
'name' => 'Post 3',
'time' => '2000/10/10 20:30',
),
);
usort(
$input,
function($a,$b){
if (strcmp($a['time'], $b['time'])>0) {
return true;
}
return false;
}
);
$output = array();
foreach($input as $row) {
$date = substr($row['time'], 0, 10);
$row['time'] = substr($row['time'], 11);
$output[$date][] = $row;
}
echo '<pre>';
var_export($output);
Output:
array (
'2000/10/10' =>
array (
0 =>
array (
'name' => 'Post 1',
'time' => '12:10',
),
1 =>
array (
'name' => 'Post 2',
'time' => '16:20',
),
2 =>
array (
'name' => 'Post 3',
'time' => '20:30',
),
),
'2000/10/11' =>
array (
0 =>
array (
'name' => 'Post 6',
'time' => '10:00',
),
),
)
Задача решена, но при чем здесь ActiveRecord?
Тоже не понял причем здесь ActiveRecord, если нужно сделать группировку по датам при выборке из базы юзайте стандартные GROUP BY DATE_FORMAT()