update_sorting_field.php 669 Bytes
Newer Older
Dainis Abols's avatar
Dainis Abols committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php

$config = require '/home/portal/typo3/typo3conf/LocalConfiguration.php';

$dsn       = 'mysql:host='.$config['DB']['Connections']['Default']['host'].';dbname='.$config['DB']['Connections']['Default']['dbname'];
$db        = new PDO($dsn, $config['DB']['Connections']['Default']['user'], $config['DB']['Connections']['Default']['password']);
$table     = "tx_lunotices_domain_model_notices";
$sql       = "UPDATE ".$table." SET sorting=? WHERE starttime=?";
$statement = $db->prepare($sql);

$sorting = 1;
foreach ($db->query("SELECT * FROM ".$table." ORDER BY starttime DESC") as $row) {
    $statement->execute([$sorting, $row['starttime']]);
    $sorting++;
}