homepage Welcome to WebmasterWorld Guest from 50.19.33.5
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe and Support WebmasterWorld
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderators: physics

Databases Forum

    
Looping through Mysql to Update fields too slow
tomhumf




msg:3999809
 11:38 am on Oct 2, 2009 (gmt 0)

Hi,

I'm trying to update a mysql table so that the url field have a nicely formatted URL. This method works but it is very slow, I have to set a big time limit so it completes. If I start using it on larger tables I imagine it will takes ages, the current table has about 3k records. Is there a faster way of doing this?

<?php

set_time_limit(200);
$sql = "SELECT * FROM table";
$result = mysql_query($sql) or die (mysql_error());
while ($row = mysql_fetch_array($result)){
$title = $row['title'];
$id = $row['id'];

$url = preg_replace("/[^a-zA-Z0-9\s]/", "", $title);
$url = strtolower(str_replace(" ","",$url));


$sql="UPDATE `table` SET `url`='$url' WHERE `id`='$id' LIMIT 1";
mysql_query($sql);
}
?>

 

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved