Что пробовал:
JSON.stringify. В итоге на выходе получаем строку, вместо объекта. Но как ее теперь закинуть в php файлик?
$json = json_decode($_POST['json']);
foreach($arr as $item){
if ( array_key_exists("tag", $item) && $item["tag"] == "plan" ) {
$link = $item["url"];
break;
}
}
<?php
echo implode( // собираем строку
",",
array_slice( // берем 3 первых эдемента
explode(",", $address), // разбиваем на массив по запятой
0,
3
)
);
preg_match_all('/,/', $address, $matches, PREG_OFFSET_CAPTURE);
echo substr($address, 0, $matches[0][2][1]);
SELECT row_to_json(client.*)
FROM (
SELECT
clients.*,
json_agg(
row_to_json(trainers.*)
) trainers
FROM
clients
JOIN trainers ON trainers.t_id < clients.t_id
where
clients.t_id = 10
GROUP BY clients.t_id, clients.t_name, clients.t_phone
) client;
SELECT json_object(
't_id' VALUE client.t_id,
't_name' VALUE client.t_name,
't_phone' VALUE client.t_phone,
't_trainers' VALUE client.trainers
) FROM (
SELECT
clients.*,
json_arrayagg(json_object(
't_id' VALUE trainers.t_id,
't_name' VALUE trainers.t_name,
't_phone' VALUE trainers.t_phone
)) trainers
FROM
clients
JOIN trainers ON trainers.t_id < clients.t_id
where
clients.t_id = 10
GROUP BY clients.t_id, clients.t_name, clients.t_phone
) client;
SELECT
*
FROM (
SELECT
url_id,
status,
updated_at,
ROW_NUMBER() OVER (PARTITION BY url_id ORDER BY updated_at DESC) rn
FROM urls_checks
ORDER BY urls_checks DESC
) checks
JOIN urls on urls.id = checks.url_id
WHERE rn = 1;
update table1
join table2 on table1.name = table2.name
set table1.total = (total - total2)
;
<?php
function getOne($conn) {
$result = mysqli_query($conn,"
SELECT *
FROM `stat`
JOIN `order` ON `order`.`id` = `stat`.`order_id`
WHERE `delivery`='Почта' AND `cost`='0'"
);
if (mysqli_num_rows($result)>0) {
while ($row = mysqli_fetch_assoc($result)) {
echo json_encode($row);
}
}
else {
echo "Ошибка в getOne";
}
mysqli_close($conn);
}
$result = mysqli_query($conn, "SELECT * FROM `country` WHERE `city`='Москва'");
$row = mysqli_fetch_assoc($result);
printf('Country ID is: %s', $row['id']);
<?php
if ($reviews) {
foreach ($reviews as $review) {
if (!preg_match('/[^A-Za-z0-9]/', $review['text'])) {
echo '<div class="review-list">
<div class="author"><b>' . $review['author'] .'</b> '. $text_on . $review['date_added'] . '</div>
<div class="rating"><img src="catalog/view/theme/default/image/stars-' . $review['rating'] . '.png" alt="' . $review['reviews'] .'" /></div>
<div class="text">' . $review['text'] .'</div>
</div>';
}
}
}
$result = array_reduce(
$data,
function($res, $el) {
if (isset($res[$el["id_product_attribute"]])) {
$res[$el["id_product_attribute"]] .= ", " . $el["attribute_name"];
} else {
$res[$el["id_product_attribute"]] = $el["attribute_name"];
}
return $res;
},
[]
);
var_export($result);
function addList($data, $conn)
{
$cart = json_decode($data["cart"], true);
$stmt = $conn->prepare(
"UPDATE `list` SET `count` = GREATEST(`count` - ?, 0) WHERE `id`= ? ;"
);
/* bind parameters for list */
$stmt->bind_param("ds", $count, $id);
foreach ($cart as $value) {
$id = $value["id"];
$count = $value["count"];
/* execute query */
$stmt->execute();
}
}
CREATE TABLE `table1` (
`id` int,
`chat` int,
`q` int,
PRIMARY KEY (`id`, `chat`)
);
INSERT INTO `table1` ( `id`, `chat`, `q` )
VALUES ( 1, 12, 1 )
ON DUPLICATE KEY UPDATE `q` = `q` + 1;
select *
from events
where
date > current_timestamp - interval '1 hour'
and type in ('open', 'open_page_1')
and not exists (
select type from events e
where e.operation_id = events.operation_id
and type not in ('open', 'open_page_1')
)
;
<?php
$str = "@User, Привет";
preg_match('/(@)([^,]+),(.+)/i', $str, $matches);
var_export($matches);
array (
0 => '@User, Привет',
1 => '@',
2 => 'User',
3 => ' Привет',
)
$query = "insert into tbl (name) values (?);";
$stmt = $pdo->prepare($query);
$stmt->execute(['jfjd']);
print 'lastInsertId: ' . $pdo->lastInsertId();
update test
set
a = replace(a, 'slovo', ''), -- заменяем часть строки
b = if(b = 'slovo1', 'slovo2', b) -- заменяем строку по условию
;
select
user_name,
coalesce(likes, 0) likes
from users
left join likes on likes.user_id = users.id;