vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Change URL to board in posts... (https://vborg.vbsupport.ru/showthread.php?t=40863)

JJR512 07-09-2002 03:44 PM

Change URL to board in posts...
 
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 04:50 PM

Use MySQL's REPLACE() function on pagetext in the post table.

JJR512 07-10-2002 12: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 Code:

<?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 05: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 06:23 AM

OK, well, can someone explain how to use that replace() funtion, exactly?

Admin 07-10-2002 11:37 AM

Code:

UPDATE post SET pagetext = REPLACE(pagetext, "find", "replace");
That's roughly the idea... back the table up first.


All times are GMT. The time now is 12:52 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01558 seconds
  • Memory Usage 1,720KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete