You are here: Re: Updating the SQL key value « PHP Programming Language « IT news, forums, messages
Re: Updating the SQL key value

Posted by bill on 03/30/07 11:38

Toby A Inkster wrote:
> 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);
> ?>
>
Lovely idea. For my small number a PHP array probably works
better, but I do like this approach and will archive it.

One additional question: does the foreach loop terminate because
the query return false ?

bill

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация