$price = $priceElem->plaintext;
$priceCleaned = str_replace(',', '.', preg_replace('/[^0-9,.]/', '', $price));
$priceN = floatval($priceCleaned);
$db->query("INSERT IGNORE INTO posts (`title`, `img`, `link`, `price`)
VALUES('{$post['title']}', '{$post['img']}', '{$post['link']}', {$priceN})");
if ($user_damage > $battle['health']) {
// Установка блокировки на таблицу `_basement_battle`
mysql_query('LOCK TABLES `_basement_battle` WRITE');
try {
mysql_query('SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE');
mysql_query('START TRANSACTION');
// Выполнение обновлений
mysql_query('UPDATE `basement_clans` SET `json_key` = JSON_SET(`json_key`, \'$."' . 'key_'.($battle['boss_id'] + 1) . '"\', JSON_EXTRACT(`json_key`, \'$."' . 'key_'.($battle['boss_id'] + 1) . '"\') + 1), `json_limit` = JSON_SET(`json_limit`, \'$."' . 'boss_'.$battle['boss_id'] . '"\', JSON_EXTRACT(`json_limit`, \'$."' . 'boss_'.$battle['boss_id'] . '"\') + 1), `json_medals` = JSON_SET(`json_medals`, \'$."' . 'boss_'.$battle['boss_id'] . '"\', JSON_EXTRACT(`json_medals`, \'$."' . 'boss_'.$battle['boss_id'] . '"\') + 1) WHERE `clan` = '.$clan['id'].' AND `jail` = '.$user['reset']);
mysql_query('DELETE FROM `_basement_battle` WHERE `id` = '.$battle['id']);
mysql_query('COMMIT');
} catch (Exception $e) {
mysql_query('ROLLBACK');
} finally {
// Снятие блокировки после выполнения транзакции
mysql_query('UNLOCK TABLES');
}
}
// Подключение к БД
$dsn = 'mysql:host=localhost;dbname=mydatabase';
$username = 'myusername';
$password = 'mypassword';
$options = array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
);
$pdo = new PDO($dsn, $username, $password, $options);
// Подготовленный запрос
$stmt = $pdo->prepare("INSERT INTO mytable (snippet, amp, date, anchor, link) VALUES (:snippet, :amp, :date, :anchor, :link)");
// Заполнение параметров запроса значениями из массива
foreach ($data as $values) {
$stmt->bindParam(':snippet', $values['snippet']);
$stmt->bindParam(':amp', $values['amp']);
$stmt->bindParam(':date', $values['date']);
$stmt->bindParam(':anchor', $values['anchor']);
$stmt->bindParam(':link', $values['link']);
// Выполнение запроса
$stmt->execute();
}
function get_custom_post_term() {
global $wpdb;
$post_id = get_the_ID(); // Получаем ID текущего поста
$term = $wpdb->get_var( $wpdb->prepare(
"SELECT t.name
FROM {$wpdb->prefix}term_taxonomy AS tt
INNER JOIN {$wpdb->prefix}term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
INNER JOIN {$wpdb->prefix}terms AS t ON t.term_id = tt.term_id
WHERE tt.taxonomy = 'curr_post_tax' AND tr.object_id = %d",
$post_id
) );
return $term;
}
$current_term = get_custom_post_term();
echo '<div>Home>Catalog>Term>'.$current_term.'</div>';
function csvToArray($csvFile){
$file_to_read = fopen($csvFile, 'r');
// Обработка BOM
$bom = fread($file_to_read, 2);
if ($bom === chr(0xff).chr(0xfe)) {
// UTF-16LE BOM найден
stream_filter_append($file_to_read, 'convert.iconv.utf-16le/utf-8');
} else {
// Нет BOM, считаем файл в текущей кодировке сервера
rewind($file_to_read);
stream_filter_append($file_to_read, 'convert.iconv.ISO-8859-1/UTF-8');
}
// Чтение CSV-файла
$lines = array();
while (!feof($file_to_read) ) {
$lines[] = fgetcsv($file_to_read);
}
fclose($file_to_read);
return $lines;
}
<?php
require_once (__DIR__.'/crest.php');
// Установите PAGE_SIZE на 1000, чтобы получать до 1000 записей за раз
$page_size = 1000;
$page = 0;
$log_items = array();
do {
$result = CRest::call(
'task.logitem.list',
array(
'ID' => 80906,
'PAGE_SIZE' => $page_size,
'PAGE' => ++$page
)
);
if (isset($result['result'])) {
$log_items = array_merge($log_items, $result['result']);
}
} while (count($result['result']) === $page_size);
echo '<pre>';
print_r($log_items);
echo '</pre>';
// Получаем JSON-строку
$json_string = '[{
"url_img":"url",
"name":"Виктор"
},{
"url_img":"url",
"name":"Анна"
}]';
// Преобразуем JSON-строку в массив PHP
$data = json_decode($json_string, true);
// Извлекаем значение поля "name" для каждого элемента в массиве
foreach ($data as $item) {
echo $item['name'] . '<br>';
}
<?php
// JSON-строка
$json_str = '{"state": 0,
"result": {
"uuid": "f1386fb5-ecfa-41d4-a85d-b151d98df5e1",
"order_id": "test-28",
"amount": "10.00000000",
"payment_amount": "11.95000000",
"payer_amount": "10.00000000",
"payer_currency": "USDT",
"currency": "USDT",
"comments": null,
"network": "tron_trc20",
"address": null,
"from": null,
"txid": null,
"payment_status": "refund_process",
"url": "https://pay.cryptomus.com/pay/f1386fb5-ecfa-41d4-a85d-b151d98df5e1",
"expired_at": 1655196355,
"status": "check",
"is_final": false,
"additional_data": null,
"currencies": [
{
"currency": "USDT",
"network": "tron_trc20"
},
{
"currency": "USDT",
"network": "eth_erc20"
}
]
}
}';
// преобразуем JSON-строку в объект
$obj = json_decode($json_str);
// получаем значение свойства url
$url = $obj->result->url;
// выводим url на страницу
echo $url;
<?php
// Массив страниц и соответствующих ссылок в меню
$menuItems = array(
"/page1" => "Ссылка 1",
"/page2" => "Ссылка 2",
"/page3" => "Ссылка 3",
"/page4" => "Ссылка 4",
);
// Получаем относительный путь
$url = $_SERVER['REQUEST_URI'];
$url = explode('?', $url);
$url = $url[0];
// Выводим ссылки в меню
foreach ($menuItems as $pageUrl => $menuItem) {
if ($pageUrl != $url) {
echo '<a href="' . $pageUrl . '">' . $menuItem . '</a>';
}
}
?>
SELECT
SUM(amount) as total_sum,
DATE_FORMAT(FROM_UNIXTIME(time), '%d.%m.%Y') as date,
SUM(CASE WHEN time > UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 DAY)) THEN amount ELSE 0 END) as day_1,
SUM(CASE WHEN time > UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 2 DAY)) AND time <= UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 DAY)) THEN amount ELSE 0 END) as day_2,
SUM(CASE WHEN time > UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 3 DAY)) AND time <= UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 2 DAY)) THEN amount ELSE 0 END) as day_3,
SUM(CASE WHEN time > UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 4 DAY)) AND time <= UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 3 DAY)) THEN amount ELSE 0 END) as day_4,
SUM(CASE WHEN time > UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 5 DAY)) AND time <= UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 4 DAY)) THEN amount ELSE 0 END) as day_5,
SUM(CASE WHEN time > UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 6 DAY)) AND time <= UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 5 DAY)) THEN amount ELSE 0 END) as day_6,
SUM(CASE WHEN time > UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 7 DAY)) AND time <= UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 6 DAY)) THEN amount ELSE 0 END) as day_7,
SUM(amount) as total_amount
FROM payments
WHERE status = 3 AND shop_id = :shop_id AND time > UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 7 DAY))