Welcome to WebmasterWorld Guest from 54.144.243.34

Forum Moderators: open

Looping through Mysql to Update fields too slow

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

5+ Year Member



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);
}
?>

 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month