PHP
- 3 ответа
- 0 вопросов
2
Вклад в тег
CREATE TABLE client_balance
(
id SMALLINT AUTO_INCREMENT,
id_client INTEGER,
balance_date_start DATETIME,
balance_start INTEGER,
balance_date_mid DATETIME,
balance_mid INTEGER,
PRIMARY KEY (id)
);
SELECT cb.*,
DATEDIFF(cb.balance_date_mid, cb.balance_date_start) AS diff
FROM client_balance AS cb
GROUP BY cb.id_client
HAVING MAX(diff);
<?php
$arr = array(
array('id'=>100, 'parentid'=>0, 'name'=>'a'),
array('id'=>101, 'parentid'=>100, 'name'=>'a'),
array('id'=>102, 'parentid'=>101, 'name'=>'a'),
array('id'=>103, 'parentid'=>101, 'name'=>'a'),
array('id'=>104, 'parentid'=>103, 'name'=>'a'),
array('id'=>105, 'parentid'=>103, 'name'=>'a'),
array('id'=>106, 'parentid'=>0, 'name'=>'a'),
array('id'=>107, 'parentid'=>106, 'name'=>'a'),
);
$new = array();
foreach ($arr as $a){
$new[$a['parentid']][] = $a;
}
$tree = createTree($new, array($arr[0]));
var_dump($tree);
function createTree(&$list, $parent){
$tree = array();
foreach ($parent as $k=>$l){
if(isset($list[$l['id']])){
$l['children'] = createTree($list, $list[$l['id']]);
}
$tree[] = $l;
}
return $tree;
}