async function get_balance(user_id) {
return new Promise((resolve, reject) => {
conn.query(
`SELECT * FROM users WHERE user_id = ${user_id}`,
(err, result) => {
if (err) {
reject(err);
}
console.log(result[0].balance) // 0 (как и надо)
resolve(result[0].balance);
},
);
});
}
const result = await get_balance(ctx.message.from.id);
Смысл двух разных вариантов для операторов "and" и "or" в том, что они работают с различными приоритетами (смотрите таблицу Приоритет выполнения операторов).
&&
- 15 строка, =
- 19 строка, and
- 23 строка.$bool = true and false;
=> ($bool = true) and false;
$bool = true && false;
=> $bool = (true && false);
$('.plus').click(...)
на $('.rasschet-tbl').on('click', '.plus', ...)
. 'lastname' => $data->message->from->last_name ?? null,
[admin_menu]
...
*#=dialplan_exec(conf-invite,s,1)
[conf-invite]
exten => s,1,Answer
same => n,Read(NUMBER,vm-enter-num-to-call)
same => n,Originate(SIP/${NUMBER},exten,conf-invite,conference,1)
exten => conference,1,Answer
same => n,ConfBridge(conference,bridge,simple-user,user_menu)
<?php
$data = [
[
'id' => 1,
'parent_id' => 100,
'name' => 'Стулья'
], [
'id' => 2,
'parent_id' => 100,
'name' => 'Столы'
], [
'id' => 5,
'parent_id' => 1,
'name' => 'Стул Сакура',
'price' => 5691,
'img' => 'lorempixel.com/900/900/?q=5',
'props' => []
], [
'id' => 9,
'parent_id' => 2,
'name' => 'Стол Византия',
'price' => 5268,
'img' => 'lorempixel.com/900/900/?q=9',
'props' => []
]
];
function build_tree($data, $id) {
$result = [];
foreach ($data as $el) {
if ($el['parent_id'] == $id) {
$newEl = $el;
$childs = build_tree($data, $el['id']);
if (count($childs) !== 0) {
$newEl['childs'] = $childs;
}
$result[] = $newEl;
}
}
return $result;
}
$tree = build_tree($data, 100);
print_r($tree);
/*
Array (
[0] => Array (
[id] => 1
[parent_id] => 100
[name] => Стулья
[childs] => Array (
[0] => Array (
[id] => 5
[parent_id] => 1
[name] => Стул Сакура
[price] => 5691
[img] => lorempixel.com/900/900/?q=5
[props] => Array ()
)
)
)
[1] => Array (
[id] => 2
[parent_id] => 100
[name] => Столы
[childs] => Array (
[0] => Array (
[id] => 9
[parent_id] => 2
[name] => Стол Византия
[price] => 5268
[img] => lorempixel.com/900/900/?q=9
[props] => Array ()
)
)
)
)
*/
SET `cte_max_recursion_depth` = 10000;
INSERT INTO `test` (`DATE_CREATE`, `DATE_UPDATE`, `ACTIVE`, `USER_ID`, `VALUE`)
WITH RECURSIVE `cte` (`DATE_CREATE`, `DATE_UPDATE`, `ACTIVE`, `USER_ID`, `VALUE`) AS (
SELECT NOW(), NOW(), 1, 1, 1 AS `VALUE`
UNION
SELECT NOW(), NOW(), 1, 1, `VALUE`+1 FROM `cte` WHERE `VALUE` < 9999
)
SELECT *
FROM `cte`