select
:id as person,
IF (person_1 = :id, person_2, person_1) person_contact
from persons
where person_1 = :id or person_2 = :id
;
$(function (){
$(document).on('click', '.pluspol',function (){
const btn = this;
//disable - prevent clicks
btn.disabled = true;
var dd = $(this).attr('data-pluspol');
var box = $(this).parent().find('.summaw');
$.ajax({
url: 'shablon/plususer.php',
type: 'POST',
data: {"dd":dd},
success: function(html){
// enable
btn.disabled = enable;
box.html(html);
}
});
});
});
<?php
$arr1 = array(
'1' => array('1' => 'значение-1-ключ-1', '2' => 'значение-2-ключ-1'),
'2' => array('1' => 'значение-1-ключ-2', '2' => 'значение-2-ключ-2'),
'3' => array('1' => 'значение-1-ключ-3', '2' => 'значение-2-ключ-3'),
);
$result = array_reduce(
$arr1,
function($res, $el) {
return array_merge($res, $el);
},
[]
);
SELECT
device_name,
COUNT(*) cnt
FROM users
WHERE
YEAR(created_date) = 2020 AND
year_of_birth < DATE_SUB(CURDATE(), INTERVAL 25 YEAR)
GROUP BY device_name;
$data = json_decode($json, true);
$data['group'] = array_reduce(
$data['group'],
function($res, $i) {
$res[$i['id']] = $i['value'];
return $res;
},
[]
);
{"group":{"12":"3","15":"1"}}
SELECT *
FROM comment
WHERE (id = 1 AND reply_id IS NULL) OR reply_id = 1;
UPDATE
`products`
SET `price` = ROUND((`price_z` / 100) * (
CASE
WHEN `price_z` BETWEEN 1 AND 100000 THEN 110
WHEN `price_z` BETWEEN 100001 AND 200000 THEN 109
WHEN `price_z` BETWEEN 200001 AND 300000 THEN 108
ELSE 107
END
))
WHERE `date_price` = CURDATE();
<?php
$arr = [
0 => '02-01',
1 => '03-15',
2 => '06-03'
];
echo json_encode($arr);
function useMobileDetectLib() {
$settings = new Fseo_Sett;
$use_lib = $settings->getSetting('use_lib');
if (is_object($use_lib) && $use_lib->value == '1') {
require_once 'Mobile_Detect.php';
}
}
PRIMARY KEY AUTO_INCREMENT
для поля `id`, и пофиксить определение поля `text`CREATE TABLE `textlog` (
`id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`chat_id` int(111) NOT NULL,
`text` text NOT NULL,
`date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
if (preg_match('/\Atest: (\d,?)+\z/', $string)) {
echo 'ok!';
} else {
echo 'not match!';
}
preg_match("/(photo|video|wall)-([\d]+_[\d]+)/i", $string, $matches);
INSERT INTO (
`from`,`to`,`in`,`out`,`minamount`,`maxamount`,`amount`
) VALUES (?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE
`in` = ?,
`out` = ?,
`minamount` = ?,
`maxamount` = ?,
`amount` = ?;
select
oi.id,
(oi.price * coalesce(wi.quantity, 0)) wi_sum,
(oi.price * coalesce(ai.quantity, 0)) ai_sum,
(oi.price * coalesce(least(wi.quantity, ai.quantity), 0)) both_sum
from order_items oi
left join waybills_items wi on wi.order_item_id = oi.id
left join acts_items ai on ai.order_item_id = oi.id
order by oi.id;
$result = mysql_query("SHOW TABLES IN `DB`");
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
print_r($row);
}
mysql_free_result($result);
<?php
$json = [
[
["id"=>1,
"login"=>'Admin'
],
null,
null,
null,
null,
null
],
'route' => true,
'spectators' => null
];
echo json_encode($json);