View Full Version : Change URL to board in posts...
JJR512
07-09-2002, 04:44 PM
I just moved my board to a different directory on the server. I moved it to the root www level. Is there a way to search through all the posts for all instances of forums.jjr512.com and replace each with www.jjr512.com?
Admin
07-09-2002, 05:50 PM
Use MySQL's REPLACE() function on pagetext in the post table.
JJR512
07-10-2002, 01:03 AM
I looked that up and didn't really understand it.
I figured a little script like this would do the trick. While it produces no errors, it also doesn't actually do anything. Can you tell me why?
<?php
error_reporting(7);
require("./global.php");
$postcount=$DB_site->query_first("SELECT count(*) AS count FROM post");
$totalposts = $postcount[count];
$postid = 1;
while ($postid <= $totalposts) {
echo $postid;
$pagetext = $DB_site->query_first("SELECT pagetext FROM post WHERE postid=$postid");
$text = $pagetext[pagetext];
$newtext = str_replace("forums.jjr512.com","www.jjr512.com",$text);
$DB_site->query("UPDATE post SET pagetext='".addslashes($newtext)."' WHERE postid='$postid'");
$postid++;
}
?>
Logician
07-10-2002, 06:15 AM
It wont work because you are assuming that postids are consecutive in db while they are not. For example you might have deleted the postid 3 in your db, however your code still tries to replace its pagetext..
If you want to stick with your code, your best bet is to get all pagetexts first with select (in 1 query) and then parse them (If your db is big this might be a problem though)
However what Firefly suggested is the best and easiest method to handle what you are trying to do, so if I were you I wouldnt bother with writing my own code.. My 2 cents..
JJR512
07-10-2002, 07:23 AM
OK, well, can someone explain how to use that replace() funtion, exactly?
Admin
07-10-2002, 12:37 PM
UPDATE post SET pagetext = REPLACE(pagetext, "find", "replace");
That's roughly the idea... back the table up first.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.