UPDATE tbl
SET link = CONCAT(
'<p>[playerjs file:\"',
MID(LEFT(link, LOCATE('?', link, LOCATE('src="', link))-1), LOCATE('src="', link)+5),
'\"]</p>'
);
<?php
function number_sum($num)
{
return array_sum(str_split($num));
}
$sum = 28;
for ($b1 = 1; $b1 < 256; $b1++) {
for ($b2 = 0; $b2 < 256; $b2++) {
for ($b3 = 0; $b3 < 256; $b3++) {
for ($b4 = 0; $b4 < 256; $b4++) {
if ((
number_sum($b1) +
number_sum($b2) +
number_sum($b3) +
number_sum($b4)
) == $sum) {
echo "$b1.$b2.$b3.$b4" . PHP_EOL;
}
}
}
}
}
в языке SQL версии СУБД MySQL предпочтительно заключение названий таблиц и их полей в косые кавычки, поскольку это предотвращает путаницу с зарезервированными именами. Например, SELECT * FROM WHERE вызовет ошибку, а SELECT * FROM `WHERE` — нет (при условии, что существует таблица WHERE).
mysqli_query($mysqli, "CREATE TABLE `$game_name` (
`game_id` INT(11) DEFAULT $output[id],
`name` VARCHAR(40) NOT NULL,
`image` VARCHAR(100),
`descr` VARCHAR(100) NOT NULL,
`percents` VARCHAR(6),
`making` TEXT(1000),
`vid_link` VARCHAR(100)
)");
Зачем нормализовать базу данных?
У Вас может возникнуть вопрос – а зачем вообще нормализовать базу данных и бороться с этой избыточностью?
Дело в том, что избыточность данных создает предпосылки для появления различных аномалий, снижает производительность, и делает управление данными не гибким и не очень удобным. Отсюда можно сделать вывод, что нормализация нужна для:
Устранения аномалий
Повышения производительности
Повышения удобства управления данными
select extract(epoch from date_trunc('day', to_timestamp(from_at))) as date;
public function foo($obj) {
if ($obj->isNotActive()) {
throw new Exception('Not active.');
}
//другие действия с объектом
return $obj;
}
try {
foo($obj);
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
if(isset($_POST['save'])) {
$name = $_POST['name'];
$product = $_POST['product'];
$price = $_POST['price'];
$email = $_POST['email'];
$uid = $_POST['uid'];
mysqli_begin_transaction($mysqli);
try {
/* Добавление значений */
$stmt = mysqli_prepare($mysqli, "INSERT INTO tovar (name,product,price,email) VALUES (?, ?, ?, ?)");
mysqli_stmt_bind_param($stmt, 'ssss', $name, $product, $price, $email);
mysqli_stmt_execute($stmt);
$stmt = mysqli_prepare($mysqli, "UPDATE shtuck SET sht = sht - 1 WHERE id=?");
mysqli_stmt_bind_param($stmt, 's', $uid);
mysqli_stmt_execute($stmt);
/* Если код достигает этой точки без ошибок, фиксируем данные в базе данных. */
mysqli_commit($mysqli);
} catch (mysqli_sql_exception $exception) {
mysqli_rollback($mysqli);
throw $exception;
}
mysqli_close($mysqli);
}
<?php
function curr_month_year() {
setlocale(LC_TIME, 'et_EE.UTF-8');
$month_year = strftime('%B %Y', time());
return $month_year;
}
echo curr_month_year();
<?php
function curr_month_year() {
setlocale(LC_TIME, 'et_EE.UTF-8');
return date('F Y');
}
echo curr_month_year();
DELETE
FROM cl_purchases
WHERE id IN (
SELECT id
FROM cl_purchases
WHERE point = 600258
AND date BETWEEN '2020-03-01 00:00:00' AND '2020-03-31 23:59:59'
AND order_type = 'delivery'
AND provider <> 'iikodelivery'
GROUP BY order_id
HAVING COUNT( id ) > 1
)
select posts.id, posts.body, sum(
case direction
when 'UP' then 1
when 'DOWN' then -1
else 0
end) likes
from posts
left join likes on likes.post_id = posts.id
group by posts.id, posts.body
order by likes desc
;
select posts.id, posts.body, (
count(nullif(direction, 'DOWN')) - count(nullif(direction, 'UP'))) likes
from posts
left join likes on likes.post_id = posts.id
group by posts.id, posts.body
order by likes desc
;
create table types (
id int auto_increment primary key,
title varchar(255)
);
insert into types (title) values ('Одежда');
create table categories (
id int auto_increment primary key,
type_id int,
title varchar(255),
foreign key (type_id) references types(id)
);
insert into categories (type_id, title) values (1, 'Брюки'), (1, 'Рубашки');
create table goods (
id int auto_increment primary key,
category_id int,
title varchar(255),
foreign key goods_category (category_id) references categories(id)
);
insert into goods (category_id, title) values (1, 'Брюки мужские'), (2, 'Рубашка поло спорт');
select
goods.id,
types.title as type,
categories.title as category,
goods.title
from goods
join categories on goods.category_id = categories.id
join types on categories.type_id = types.id
;
select * from tbl
where from_id + to_id = 20 + 32 and abs(from_id - to_id) = abs(20 - 32);
SELECT
user_id,
MIN(current_status) current_status,
MIN(dateadd) dateadd,
status_changed
FROM
(
SELECT
tt.*,
MIN(tt1.dateadd) as status_changed
FROM
`test_table` tt
LEFT JOIN `test_table` tt1 ON tt1.user_id = tt.user_id
AND tt1.dateadd > tt.dateadd
AND tt1.current_status <> tt.current_status
GROUP BY
tt.id,
tt.current_status,
tt.user_id
) aggregated
GROUP BY
user_id,
status_changed
ORDER BY
dateadd;
+=========+================+=====================+=====================+
| user_id | current_status | dateadd | status_changed |
+=========+================+=====================+=====================+
| 3 | new | 2020-10-01 03:00:59 | 2020-10-11 02:00:59 |
+---------+----------------+---------------------+---------------------+
| 3 | old | 2020-10-11 02:00:59 | 2020-10-11 05:00:59 |
+---------+----------------+---------------------+---------------------+
| 3 | new | 2020-10-11 05:00:59 | 2020-11-01 03:00:59 |
+---------+----------------+---------------------+---------------------+
| 3 | old | 2020-11-01 03:00:59 | 2020-11-12 03:00:59 |
+---------+----------------+---------------------+---------------------+
| 3 | new | 2020-11-12 03:00:59 | 2020-11-15 03:00:59 |
+---------+----------------+---------------------+---------------------+
| 3 | old | 2020-11-15 03:00:59 | (null) |
+---------+----------------+---------------------+---------------------+
<?php
$mystring = "The new brave world!";
$delimiter = ' ';
echo explode($delimiter, $mystring, 2)[1];
echo PHP_EOL;
echo trim(strstr($mystring, $delimiter));
echo PHP_EOL;
echo substr($mystring, strpos($mystring, $delimiter)+1);
echo PHP_EOL;
create table `calendar` (
`event` varchar(64),
`year` smallint unsigned,
`month` tinyint unsigned,
`day` tinyint unsigned,
`hour` tinyint unsigned,
`minute` tinyint unsigned
);
insert into calendar values
('December 31 every year at 23:55', null, 12, 31, 23, 55),
('every minute in december 2020', 2020, 12, null, null, null),
('every hour at first of month', null, null, 1, null, 0)
;
select `event`
from `calendar`
where
(`year` is null or `year` = year(now())) and
(`month` is null or `month` = month(now())) and
(`day` is null or `day` = day(now())) and
(`hour` is null or `hour` = hour(now())) and
(`minute` is null or `minute` = day(now()))
;
select *
from myproducts
join (
select distinct product_id
from myproducts
order by product_id
limit 20 -- количество уникальных товаров
) unique_products on unique_products.product_id = myproducts.product_id;