You are here: Re: [PHP] SELECT? « PHP « IT news, forums, messages
Re: [PHP] SELECT?

Posted by Paul Waring on 12/28/05 13:28

On 12/28/05, William Stokes <kalles@operamail.com> wrote:
> I have one MySQL table with about 500 rows. I need to read the table one row
> at a
> time, make some changes to data in one field and then store the changed data
> to another table.
>
> I'm using PHP to change the data but I have no idea how to select one row at
> a time from the DB table. There's one auto-increment id field in the table
> but the id's doesn't start from 1 and are not sequential.
>
> Any ideas or help is much appreciated!

Can you not just fetch all the data at once like so:

$result = mysql_query("SELECT * FROM mytable");

then iterate over the results:

while ( $row = mysql_fetch_assoc($result) )
{
mysql_query("INSERT INTO othertable (column1) VALUES (" .
$row['column_x'] . ");
}

The only thing you'd have to be careful with is the maximum execution
time settings if you're running this script over the web, as opposed
to on the command line. If you're only making changes to 500 rows
though it shouldn't take too long - I've restored thousands of rows to
a database before and that took less than a second.

Paul

--
Data Circle
http://datacircle.org

 

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

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