if (preg_match('/^\+7 \(\d{3}\) \d{3}-\d{2}-\d{2}$/', $login_phone)) {
echo 'ok';
} else {
echo 'wrong number';
}
CREATE TABLE sportsmans(
id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
full_name VARCHAR(255),
email VARCHAR(255),
phone_number VARCHAR(11),
birthday date,
passport_number int(15),
average_rate int(11),
biography text,
video VARCHAR(255),
created_at datetime
);
preg_match_all('/<paramname>(.+)<\/paramname>/', $text, $matches); // <![CDATA[Модель]]>
preg_match_all('/<paramname><!\[CDATA\[(.+)\]\]><\/paramname>/', $text, $matches); //Модель
select n from unnest(array[1, 3, 5, 7]) n
left join test on n = id
where id is null;
select
row.user_id, count(*) matches_row_count
from users user_row
join users row on
(user_row.a_id = row.a_id) and
(user_row.b_id = row.b_id) and
(user_row.id != row.user_id)
where user_row.user_id = 1
group by row.user_id;
<?php
function get_categoies($pdo)
{
$stmt = $pdo->prepare("SELECT * FROM `categories`");
$stmt->execute();
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
function get_prices_by_category($pdo, $category_id)
{
$stmt = $pdo->prepare("SELECT * FROM `prices` WHERE category_id = ?");
$stmt->execute([$category_id]);
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
$categories = get_categoies($pdo);
foreach ($categories as $category) {
echo '<h3>'.$category['title'].'</h3>
<div class="cblock">';
$prices = get_prices_by_category($pdo, $category['id']);
foreach ($prices as $price) {
echo '<div class="pricelist-row">
<div class="service">' . $price["title"] . '</div>
<div class="price">от ' . $price["price"] . ' руб/' . $price["type"] . '</div>
</div>';
}
echo '</div>';
}
SELECT user_id, count(distinct created)
FROM orders
WHERE created > DATE_SUB(CURRENT_DATE, INTERVAL 30 DAY) -- get last 30 day orders
GROUP BY user_id
HAVING count(distinct created) = 30 -- check user have orders in 30 different days
;
<?php
//Есть массив
$arr=['a','d','x','d','d','d','a','z','z','f','f','f','f','b','c','v'];
echo '<div>' . PHP_EOL;
foreach ($arr as $i=>$el) {
if ($i > 0 && $el <> $arr[$i - 1] ) echo '</dv><div>' . PHP_EOL;
echo $el . PHP_EOL;
}
echo '</div>';
select count(id) users_with_first_day_order
from users
where exists (
select 1 from orders where orders.user_id = users.id and orders.order_date = users.registration_date
);
select
*
from
orders
where
exists (
select
1
from
order_product
where
order_id = orders.id
and importance = 0
);
SELECT * FROM texttable
ORDER BY name REGEXP '^[А-Яа-я]' DESC, name;
SELECT Запись_на_прием.ID_Записи, Водитель.ФИО Водитель, Врач.ФИО Врач
FROM Запись_на_прием
JOIN Пользователь AS Водитель ON Водитель.ID_Пользователя = Запись_на_прием.ID_Водитель
JOIN Пользователь AS Врач ON Врач.ID_Пользователя = Запись_на_прием.ID_Врач
;