Re: SELECT?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 12/28/05, William Stokes <kalles@xxxxxxxxxxxxx> 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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux