function group_days($block) {
$week = array('Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб');
$res = [];
foreach ($block as $id=>$day) {
if ($id == 0) {
$period = [$day];
} else {
if (array_search($day, $week)-array_search(end($period), $week)==1) {
$period[1] = $day;
} else {
$res[] = $period;
$period = [$day];
}
}
}
$res[] = $period;
$res = array_map(
function($el) {return implode('-', $el);},
$res
);
return implode(', ', $res);
}
SELECT
GROUP_CONCAT('select "' || name || '" table_name, * from `' || name || '` where referer = "yandex"', ' union ') q
FROM
sqlite_master
WHERE
type ='table' AND
name NOT LIKE 'sqlite_%';
select "t1" table_name, * from t1 where referer = "yandex" union select "t2" table_name, * from t2 where referer = "yandex"
+============+====+=========+
| table_name | id | referer |
+============+====+=========+
| t1 | 2 | yandex |
+------------+----+---------+
| t2 | 20 | yandex |
+------------+----+---------+
select string_agg(substring, '') from (
SELECT
substring('ABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil(random() * 26)::integer, 1)
FROM generate_series(1,12) -- 12 capital letters
union
SELECT
substring('abcdefghijklmnopqrstuvwxyz', ceil(random() * 26)::integer, 1)
FROM generate_series(1,12) -- 12 low case letters
union
SELECT
substring('0123456789', ceil(random() * 10)::integer, 1)
FROM generate_series(1,6) -- 6 digits
union
SELECT
substring('!#$%&()*+,-./:;<=>?@[]^', ceil(random() * 23)::integer, 1)
FROM generate_series(1,2) -- 2 other chars
) seria;
select dates.date_time dates, count(distinct tbl.user_id), sum(tbl.price)
from (
select distinct date(tbl.date_time) date_time from tbl
) dates
join tbl on dates.date_time >= date(tbl.date_time)
group by dates.date_time
order by dates.date_time;
create extension if not exists pgcrypto;
select encode(gen_random_bytes(32),'base64');
$decoded = json_decode($result, true);
var_dump($decoded['success']);
$result = array_map(
function($el) {
return explode('-', $el); // превращаем каждую пару в массив
},
explode(',', $text) // разбиваем на пары по запятой
);
with cte_orders(row_id, parent_id, group_name) as (
select row_id, parent_id, group_name from Orders where row_id = @f
union all
select O.row_id, O.parent_id, O.group_name
from Orders O
join cte_orders on cte_orders.row_id = O.parent_id
)
select sum(price) total_pice from cte_orders
left join OrderItems on cte_orders.row_id = OrderItems.order_id ;
select
customer_id,
Customers.name,
count(distinct order_id) all_orders,
count(distinct case when OrderItems.name = N'Кассовый аппарат' then order_id end) cash_machine_orders
from Orders
join OrderItems on Orders.row_id = OrderItems.order_id
join Customers on Customers.row_id = customer_id
where Orders.registered_at between '2020/01/01' and '2020/12/31'
group by Customers.name, customer_id
having count(distinct order_id) = count(distinct case when OrderItems.name = N'Кассовый аппарат' then order_id end)
;
select STRING_AGG(Name, ',') as Names, Salary from Workers group by Salary;
<?php
$items = [
['ID' => 80433, 'post_title' => 'Консоль из нержавеющей 1'],
['ID' => 80428, 'post_title' => 'Комод из неражавеющей 2']
];
$categories = ['Консоль', 'Комод'];
$result = [];
foreach($categories as $category) {
$results[$category] = [];
foreach($items as $item) {
if (mb_strpos(mb_strtolower($item['post_title']), mb_strtolower($category)) !== false) {
$result[$category][] = $item;
}
}
}
print_r($result);
<?php
бла-бла-бла ...
если (пользователь с таким именем существует) {
сообщение об ошибке
переход на страницу регистрации
закончили скрипт
}
если (пароль не совпадает с подтверждением) {
сообщение об ошибке
переход на страницу регистрации
закончили скрипт
}
если (не смогли переместить файл с аватаркой) {
сообщение об ошибке
переход на страницу регистрации
закончили скрипт
}
сохраняем нового пользователя в базу данных
сообщение об успешной регистрации
переход на страницу логина
закончили скрипт
?>
<?php
require_once 'vendor/connect.php';
$login = mysqli_real_escape_string($connect, $_SESSION["login"]);
$query = mysqli_query($connect, "SELECT * FROM `users` WHERE login = '$login'");
$balance = mysqli_fetch_assoc($query);
echo 'Balance:' . $balance['balance']. PHP_EOL;
if(isset($_POST['click'])) {
mysqli_query($connect, "UPDATE `users` SET `balance`=`balance`+0.001 WHERE login = '$login'");
echo 'New balance:' . ($balance['balance'] + 0.001) . PHP_EOL;
}
?>
<?php
require_once 'vendor/connect.php';
/* prepare statement */
$stmt = $connect->prepare("SELECT `balance` FROM `users` WHERE login = ? ");
/* bind parameters for login */
$stmt->bind_param("s", $_SESSION["login"]);
/* execute query */
$stmt->execute();
$stmt->bind_result($balance);
/* fetch value */
$stmt->fetch();
/* free result to next use */
$stmt->free_result();
echo 'Balance:' . $balance . PHP_EOL;
if (isset($_POST['click'])) {
/* prepare statement */
$stmt = $connect->prepare("UPDATE `users` SET `balance`=`balance`+0.001 WHERE login = ? ");
/* bind parameters for login */
$stmt->bind_param("s", $_SESSION["login"]);
/* execute query */
$stmt->execute();
echo 'New balance:' . ($balance['balance'] + 0.001) . PHP_EOL;
}
?>
$stmt = $conn->prepare(
"UPDATE `sortlist`
SET
`count1` ='count1' + ? ,
`count2` ='count2' + ? ,
`count3` ='count3' + ?
WHERE `id`= ? ;"
);
$stmt->bind_param('iiis', $count1, $count2, $count3, $row);
foreach ($data as $value) {
list($row, $col) = explode("-", $value['id']);
$count1 = 0;
$count2 = 0;
$count3 = 0;
$column = "count" . intval($col);
$$column = $value["count"];
echo "$count1, $count2, $count3, $row";
$stmt->execute();
}
DELETE FROM dle_comments
WHERE NOT EXISTS (SELECT 1 FROM dle_post WHERE dle_post.id = dle_comments.post_id);
DELETE dle_comments.*
FROM dle_comments
LEFT JOIN dle_post ON dle_post.id = dle_comments.post_id
WHERE dle_post.id IS NULL;
const arr = await getStartEndDateInTradePage.findAll(
{
attributes: ['open_date', 'close_date'],
where: {
close_date: {
[Op.ne]: '-'
}
}
}
)