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

Posted by Toby A Inkster on 04/02/07 09:36

bill wrote:

> I am stuck using 4.x because my hosting company does not have
> PHP5 available, yet.
> What would be the php 4 code ?

I'm not really familiar with the MySQL functions in PHP, because I use a
decent database; and it's been a while since I upgraded away from PHP 4,
but it should be something like this:

<?php
$db = mysql_connect(/* connection settings */);
mysql_select_db($db, 'some_database');
mysql_query($db, "ALTER TABLE foobar ADD tempcol integer;");
$count = 0;
$rs = mysql_query($db, "SELECT order FROM foobar ORDER BY order;");
while ($row = mysql_fetch_array($rs))
{
$count+=10;
mysql_query($db, sprintf("UPDATE foobar SET tempcol=%d WHERE order=%d;"
$count, $row['order']));
}
mysql_query($db, "UPDATE foobar SET order=tempcol;");
mysql_query($db, "ALTER TABLE foobar DROP tempcol;");
unset($count, $rs);
?>

--
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!

 

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

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