Вот мой код, добавление первых данных (с интервалом в три строки).
<?php
include "config.php";
echo time();
?>
<script src="https://mysite5.su/js/jquery-1.9.1.js"></script>
<link rel="StyleSheet" type="text/css" href="style.css">
<?php
//Выбираем все записи из attachment
try {
$query = "SELECT * FROM attachment";
$STH = $dbh->prepare($query);
$STH->execute();
$items = $STH->fetchAll(PDO::FETCH_ASSOC);
$STH = $dbh->prepare($query);
$STH->execute();
}
catch(PDOException $e) {
echo "Обнаружена ошибка. Напишите администратору. $email<br>";
file_put_contents('PDOErrors.txt', $e->getMessage(), FILE_APPEND);
}
try {
$query = "SELECT t3.*
FROM (
SELECT t1.*, count(t2.id)+1 as nr
FROM download t1
LEFT
JOIN download t2
ON t2.id < t1.id
GROUP
BY t1.id
) as t3
WHERE nr%4=1;";
$STH = $dbh->prepare($query);
$STH->execute();
$news = $STH->fetchAll();
$STH = $dbh->prepare("UPDATE download SET id_pos = ? WHERE id = ?");
foreach ( $news as $key=>$n ) {
$STH->execute(array($items[$key]["id"], $n["id"]));
}
}
catch(PDOException $e) {
echo "Обнаружена ошибка. Напишите администратору. $email<br>";
file_put_contents('PDOErrors.txt', $e->getMessage(), FILE_APPEND);
}
?>