Re: Updating the SQL key value
- From: bill <nobody@xxxxxxxxxxx>
- Date: Fri, 30 Mar 2007 07:38:45 -0400
Toby A Inkster wrote:
bill wrote:Lovely idea. For my small number a PHP array probably works better, but I do like this approach and will archive it.
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);
?>
One additional question: does the foreach loop terminate because the query return false ?
bill
.
- Follow-Ups:
- Re: Updating the SQL key value
- From: Toby A Inkster
- Re: Updating the SQL key value
- References:
- Updating the SQL key value
- From: bill
- Re: Updating the SQL key value
- From: Toby A Inkster
- Updating the SQL key value
- Prev by Date: Re: Updating the SQL key value
- Next by Date: Re: Encoding/characterset/font family confusion
- Previous by thread: Re: Updating the SQL key value
- Next by thread: Re: Updating the SQL key value
- Index(es):
Relevant Pages
|