Posted by Toby A Inkster on 03/29/07 16:02
bill wrote:
> The problem may come in using a renumber function which should
> take the steps in their current order and reassign the "order"
> key, assigning each set an "order" that is the prior "order" + 10.
Something like:
<?php
$db = new PDO(/* connection settings */);
$db->query("ALTER TABLE foobar ADD tempcol integer;");
$update = $db->prepare("UPDATE foobar SET tempcol=? WHERE order=?;");
$count = 0;
foreach ($db->query("SELECT order FROM foobar ORDER BY order;") as $row)
{
$count+=10;
$update->execute($count, $row['order']);
}
$db->query("UPDATE foobar SET order=tempcol;");
$db->query("ALTER TABLE foobar DROP tempcol;");
unset($count, $update);
?>
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux
* = I'm getting there!
[Back to original message]
|