DELIMITER $$
USE `test`$$
DROP PROCEDURE IF EXISTS `get_summed_data`$$
CREATE PROCEDURE `get_summed_data`(IN ids TEXT)
BEGIN
DECLARE iterator INT;
DECLARE number_of_ids INT;
DECLARE id_start_position INT;
DECLARE id_end_position INT;
DECLARE test_value INT;
DROP TEMPORARY TABLE IF EXISTS `tmp_get_summed_data_ids`;
CREATE TEMPORARY TABLE `tmp_get_summed_data_ids` (
`id` INT(11) NULL DEFAULT NULL,
`value` INT(11) NULL DEFAULT NULL
);
SET number_of_ids = ROUND((LENGTH(ids) - LENGTH(REPLACE(ids, ",", ""))) / LENGTH(","))+1;
SET iterator = 0;
SET id_start_position = 1;
WHILE (iterator < number_of_ids) DO
SET id_end_position = CASE
WHEN (LOCATE(',', ids, id_start_position) > 0) THEN
LOCATE(',', ids, id_start_position)
ELSE
LENGTH(ids)+1
END;
SET @id = SUBSTRING(ids, id_start_position, id_end_position-id_start_position);
SET test_value = (SELECT `value` FROM `test` WHERE `id` = @id);
INSERT INTO `tmp_get_summed_data_ids` VALUES (@id, test_value);
SET id_start_position = id_end_position+1;
SET iterator = iterator+1;
END WHILE;
SELECT SUM(`value`) AS 'sum' FROM `tmp_get_summed_data_ids`;
END$$
DELIMITER ;
CALL get_summed_data('1,1,2');
## Загрузка данных из CSV:
LOAD DATA INFILE 'p2.txt' INTO TABLE `table`
FIELDS TERMINATED BY ';' ENCLOSED BY '"'
LINES TERMINATED BY '\r\n';
## Удаление дубликатов
ALTER IGNORE TABLE `table` ADD UNIQUE INDEX tmp(column2)
$str = "Основателем социальной сети ВКонтакте был [id1|Павел Дуров]";
if (preg_match_all("/\[.*\]/m", $str, $matches)) {
foreach ($matches[0] as $match) {
list($id, $name) = explode("|", substr($match, 1, -1));
$link = "<a href='http://vk.com/{$id}' target='_blank'>{$name}</a>";
var_dump($link);
}
}
Кроме прочего, там уже добавлено @ini_set(‘date.timezone’, ‘Moscow/Europe’);
date("m", strtotime("+1 month"));
Relative month values are calculated based on the length of months that they pass through. An example would be "+2 month 2011-11-30", which would produce "2012-01-30". This is due to November being 30 days in length, and December being 31 days in length, producing a total of 61 days.
$next_month = date("m")+1 > 12 ? 1 : date("m")+1;
$post_next_month = $next_month+1 > 12 ? 1 : $next_month+1;
SELECT
`name`,
(SELECT
SUBSTRING_INDEX(
GROUP_CONCAT(`images`.`name` SEPARATOR ","),
",",
5
)
FROM `images`
WHERE `images`.`album_id`=`albums`.`album_id`
ORDER BY `images`.`image_id` DESC
)
FROM `albums`
ORDER BY `album_id` DESC
LIMIT 10
SELECT
`albums`.`name`,
CONCAT_WS(',',
(SELECT `images`.`name`
FROM `images`
WHERE `images`.`album_id`=albums.`album_id`
ORDER BY `images`.`image_id` DESC
LIMIT 0,1
),
(SELECT `images`.`name`
FROM `images`
WHERE `images`.`album_id`=albums.`album_id`
ORDER BY `images`.`image_id`
DESC LIMIT 1,1
),
(SELECT `images`.`name`
FROM `images`
WHERE `images`.`album_id`=albums.`album_id`
ORDER BY `images`.`image_id`
DESC LIMIT 2,1
),
(SELECT `images`.`name`
FROM `images`
WHERE `images`.`album_id`=albums.`album_id`
ORDER BY `images`.`image_id`
DESC LIMIT 3,1
),
(SELECT `images`.`name`
FROM `images`
WHERE `images`.`album_id`=albums.`album_id`
ORDER BY `images`.`image_id`
DESC LIMIT 4,1
)
) AS 'images'
FROM `albums`
ORDER BY `album_id` DESC
LIMIT 10
SELECT
`name`,
(SELECT
GROUP_CONCAT(innerquery.`name`)
FROM
(SELECT `images`.`name`
FROM `images`
WHERE `images`.`album_id`=`albums`.`album_id`
ORDER BY `images`.`image_id` DESC
LIMIT 5
) AS innerquery
)
FROM `albums`
ORDER BY `album_id` DESC
LIMIT 10