$data = array(0 => array(273 => 'Business', 317 => 'Rent', 377 => 'Places'),
273 => array(1676 => 'Corporations', 775 => 'Vacations', 1384 => 'Services'),
317 => array(774 => 'Car', 901 => 'Bike'),
377 => array(520 => 'Restaurants', 364 => 'Bars', 767 => 'Parcks')
);
function makeTree($data, $level, $root) {
if (!isset($data[$root]))
return "";
$str = "";
foreach($data[$root] as $id => $name) {
$str .= "<li data-id='{$id}' class='level{$level}'>${name}";
$str .= makeTree($data, $level+1, $id);
}
return ("" == $str ? "" : "<ul>{$str}</ul>");
}
print makeTree($data, 0, 0);
SELECT ...
FROM `products` AS `p`
JOIN `product_attributes` AS `pa1` ON `pa1`.`attribute_id` = :attr1
AND `pa1`.`attribute_value` = :val1 AND `pa1`.`product_id` = `p`.`id`
JOIN `product_attributes` AS `pa2` ON `pa2`.`attribute_id` = :attr2
AND `pa2`.`attribute_value` = :val2 AND `pa2`.`product_id` = `p`.`id`
int value = 13;
int base = 2;
int rank = 1;
while (rank*base <= value)
rank *= base;
while (rank) {
printf("%d", value/rank);
value %= rank;
rank /= base;
}
Запрос выполняется 8-10 секунд. Причем если меняю GROUP BY CEIL(`timestamp` / 864000) на просто GROUP BY `timestamp`, то запрос выполняется меньше чем за 1 секунду.
SELECT `p`.`id`, `p`.`title`, `p`.`slug`, `p`.`label`, `p`.`price`, `p`.`old_price`, `p`.`category_id`, `p`.`picture_id`, `p`.`brand_id`
FROM `products` AS `p`
LEFT JOIN `brands` AS `b` ON `b`.`id` = `p`.`brand_id`
WHERE `p`.`title` LIKE '%лампа%' OR `b`.`title` LIKE '%лампа%' OR `b`.`tags` like '%лампа%'
GROUP BY `products`.`id` order by `products`.`sales` desc, `products`.`views` desc
LIMIT 18