I wrote the following code to take the word "The" out of titles in my movie/book db. I ran the script for "A" and "An", and it worked just fine, updating all the records. When I ran it for "The", it updated two titles and then the query died on the third title. I thought maybe the server was down so I tried to run it later but it just dies everytime now.
Thanks
Dave Reynolds
/ test Title string to see if it begins with a, an, the. /
include ("functions.inc");
db_connect();
$query = "SELECT Title FROM my_table WHERE Title REGEXP '^The '";
$result = mysql_db_query ("my_db", $query)
or die ("Cannot EXECUTE query");
$num_results = mysql_num_rows($result);
for ($i=0; $i < $num_results; $i++)
{
$row = mysql_fetch_array($result);
$old_title = $row["Title"];
$length = strlen($row["Title"]);
$length = $length-1;
$new_title = substr($row["Title"], 4, $length);
$query_a = "UPDATE my_table SET Title='$new_title' WHERE Title='$old_title'";
$result_a = mysql_db_query ("my_db", $query_a)
or die ("Cannot EXECUTE update query");
echo "$new_title was updated";
}