<?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;
}
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);
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join('C:\PythonProject\name.project\app\static'),
]
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
CREATE TABLE product_a
(
id SMALLINT AUTO_INCREMENT,
name_a VARCHAR(10),
code_a INTEGER,
PRIMARY KEY (id)
);
CREATE TABLE product_b
(
id SMALLINT AUTO_INCREMENT,
name_b VARCHAR(10),
code_b INTEGER,
PRIMARY KEY (id)
);
INSERT INTO product_b VALUES (null, 'prod_b_3', 300);
ALTER TABLE product_a ADD name_b VARCHAR(10);
UPDATE product_a AS pa
SET pa.name_b = (SELECT pb.name_b FROM product_b AS pb WHERE pb.code_b = pa.code_a);
resp = {
'data': {
'info': {
'product_1': {
'prodinfo': 1
},
'product_2': {
'prodinfo': 2
},
'product_3': {
'prodinfo': 3
}
}
}
}
products_key = [x for x in resp['data']['info'].keys()]
print(products_key)
products = []
for key in products_key:
products.append(resp['data']['info'][key])
print(products)