homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

Looping through Mysql to Update fields too slow

5+ Year Member

Msg#: 3999807 posted 11:38 am on Oct 2, 2009 (gmt 0)


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?


$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";


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.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved