$time = '123h 5 m 07s';
if (preg_match('~(\d+)\s*h~', $time, $match)
$hours = $match[1];
if (preg_match('~(\d+)\s*m~', $time, $match)
$minutes = $match[1];
if (preg_match('~(\d+)\s*s~', $time, $match)
$seconds = $match[1];
SELECT `ui`.`id` AS `image_id`,
`ui`.`user_id` AS `user_id`,
`ui`.`create_date` AS `image_create_date`,
`ui`.`name` AS `image_name`,
`ui`.`title` AS `image_title`,
`ui`.`descr` AS `image_descr`,
`ui`.`views` AS `image_views`,
`ui`.`plus` AS `image_plus`,
`ui`.`minus` AS `image_minus`,
`bu`.`first_name` AS `user_first_name`,
`bu`.`last_name` AS `user_last_name`,
`bu`.`photo` AS `user_photo`,
COUNT(`c`.`id`) AS `com_cnt`
FROM `user_images` AS `ui`
LEFT JOIN `bpl_users` AS `bu` ON `bu`.`id` = `ui`.`user_id`
LEFT JOIN `comments` AS `c` ON `c`.`image_id` = `ui`.`id`
GROUP BY `ui`.`id`
ORDER BY `ui`.`create_date` DESC LIMIT 9
CREATE INDEX `image_id_idx` ON `comments` (`image_id`);
$arr = array('word1', 'word2', 'word3');
$n = count($arr);
for ($i = 1; $i <= $n; $i++) {
$pos[$i] = $i-1;
$c[$i] = 1;
$pr[$i] = 1;
}
$c[$n] = 0;
foreach($pos as $p)
echo $arr[$p],' ';
echo "<br>";
$i = 1;
while ($i < $n) {
$i = 1;
$x = 0;
while ($c[$i] == $n-$i+1) {
$pr[$i] = 1-$pr[$i];
$c[$i] = 1;
$x += $pr[$i];
$i++;
}
if ($i < $n) {
$k = $pr[$i] ? $c[$i]+$x : $n-$i+1-$c[$i]+$x;
$t = $pos[$k];
$pos[$k] = $pos[$k+1];
$pos[$k+1] = $t;
foreach($pos as $p)
echo $arr[$p],' ';
echo "<br>";
$c[$i]++;
}
}
word1 word2 word3
word2 word1 word3
word2 word3 word1
word3 word2 word1
word3 word1 word2
word1 word3 word2