ALTER TABLE `statistic` DROP INDEX `date`;
ALTER TABLE `statistic` ADD INDEX `date` (`date`);
$news = R::find("news", " title LIKE ? ", ["%$word%"]);
foreach ($news as $entry) {
echo "<h5>{$entry['title']}</h5>";
}
The asterisk serves as the truncation (or wildcard) operator. Unlike the other operators, it should be appended to the word to be affected. Words match if they begin with the word preceding the * operator.
If a word is specified with the truncation operator, it is not stripped from a boolean query, even if it is too short (as determined from the ft_min_word_len setting) or a stopword. This occurs because the word is not seen as too short or a stopword, but as a prefix that must be present in the document in the form of a word that begins with the prefix. Suppose that ft_min_word_len=4. Then a search for '+word +the*' will likely return fewer rows than a search for '+word +the':
The former query remains as is and requires both word and the* (a word starting with the) to be present in the document.
The latter query is transformed to +word (requiring only word to be present). the is both too short and a stopword, and either condition is enough to cause it to be ignored.
Правильно ли выглядит аналогичный запрос методом QueryBuilder?
->andWhere('h.context->>"current_user" = :id')
Подскажите, что говорит следующий код:
UPDATE
`wp_posts`
SET
`post_title` = CONCAT(
LEFT(post_title, LOCATE(' ', post_title)-1),
' №',
SUBSTR(post_title, LOCATE(' ', post_title))
)
WHERE
`post_type`='post'
ORDER BY
`post_date`
SELECT
`category`.`title`,
CONCAT(
'{',
'"hasMore":', IF(COUNT(`product`.`id`)>3, 'true', 'false'), ', ',
'"products":[',
COALESCE(GROUP_CONCAT(
JSON_OBJECT('id', `product`.`id`, 'title', TRIM(`product`.`title`))
ORDER BY `product`.`title` ASC
LIMIT 3
)),
']',
'}'
) AS product
FROM
`category`
LEFT JOIN `product` ON (`category`.`id`=`product`.`category_id`)
GROUP BY `category_id`
SET SESSION group_concat_max_len = 1000000;
<?php foreach ($categories as $category) { ?>
<h3><?= $category->title ?></h3>
<?php $products = json_decode($category->products) ?>
<?php if (!empty($category->hasMore)) { ?>
<?php foreach ($products as $product) { ?>
<span>Id: <?= $product->id ?>, Title: <?= $product->title ?></span>
<?php } ?>
<?php } ?>
<?php if (!empty($category->hasMore)) { ?>
<a>Смотреть больше</a>
<?php } ?>
<?php } ?>
Уверен, что задача простая, но я никак не соображу.
Предположим есть следующая структура в таблице БД.
Users
1.id
2.name
3.affiliated_by
function buildAffiliateChain($for, $users) {
$chain = [];
$affiliatedUsers = array_values(array_filter($users, function($user) use ($for) {
return $user['affiliated_by'] === $for;
}));
foreach ($affiliatedUsers as $affiliatedUser) {
$subscequentChain = buildAffiliateChain($affiliatedUser['id'], $users);
$chain = array_merge($chain, [$affiliatedUser], $subscequentChain);
}
usort($chain, function($someUser, $otherUser) {
return $someUser['affiliated_by'] > $otherUser['affiliated_by'] ? 1 : -1;
});
return $chain;
}
SELECT
`product`.*,
SUM(`pay`.`sum`)/`product`.`price`*100 AS 'percent' -- исправьте эту строку, применив правильную формулу.
FROM
`product`
JOIN `pay` ON `product`.`paysystem_id` = `pay`.`pay_id`
GROUP BY `product`.`id`
<?php foreach ($products as $product): ?>
<?= $product['percent'] ?>
<?php endforeach; ?>
Только остался вопрос, почему этот код в phpmyadmin не работает?