Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Woe is me... replace words in db
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Woe is me... replace words in db

 Post Reply Post Reply Page  12>
Author
Nischint View Drop Down
Groupie
Groupie
Avatar

Joined: 26 August 2002
Location: India
Status: Offline
Points: 62
Post Options Post Options   Thanks (0) Thanks(0)   Quote Nischint Quote  Post ReplyReply Direct Link To This Post Topic: Woe is me... replace words in db
    Posted: 21 June 2003 at 11:19am

Recently, I decided to change the name of a directory, from stuff to info. So all files within the stuff folder, were moved to the info folder.

That's when the problems started.

I have some 100 records in a DB which may or may not contain the line <a href="../stuff/default.asp">Link</a> .

How do I change all occurences of such links into <a href="../info/default.asp">Link</a> ?

Do I have to download the database, and physically change all 100 records? Do I update each and every record and replace stuff with info?

I see either as being too much work. Isn't there any other solution??

Maybe creating a constant that every instance of ../stuff/ be replaced by ../info/???

A better idiot

Jam Like That
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 21 June 2003 at 2:27pm
replace(rs("link"), "stuff", "info") that should help...
Back to Top
b_bonnett View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Location: New Zealand
Status: Offline
Points: 275
Post Options Post Options   Thanks (0) Thanks(0)   Quote b_bonnett Quote  Post ReplyReply Direct Link To This Post Posted: 21 June 2003 at 3:44pm
Do While Not rsWhatever.EOF
strLink = rsWhatever.Fields("link")
strLink = Replace(strLink, "../stuff", "../info")
rsWhatever.Fields("link") = strLink
rsWhatever.Update
rsWhatever.MoveNext
Loop

Hope this helps,
Blair
Webmaster, The Plane Gallery
Greetings From Christchurch
Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post Posted: 22 June 2003 at 3:23am

looking at a bigger project...

i am about to re-release my site and it'll have tons of "bad" links in it....

so i am going to use a custom 404 error page ("page not found" error) and look in the page for pages that i know will be accessed... and have a huge select statement to redirect to the right page

hopefully it works out

Contribute to the working anarchy we fondly call the Internet
Back to Top
ljamal View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Status: Offline
Points: 888
Post Options Post Options   Thanks (0) Thanks(0)   Quote ljamal Quote  Post ReplyReply Direct Link To This Post Posted: 22 June 2003 at 10:04am
Originally posted by b_bonnett b_bonnett wrote:

Do While Not rsWhatever.EOF
strLink = rsWhatever.Fields("link")
strLink = Replace(strLink, "../stuff", "../info")
rsWhatever.Fields("link") = strLink
rsWhatever.Update
rsWhatever.MoveNext
Loop

Hope this helps,
Blair


Why run a loop? Or even run via ASP or VBScript?
Just run the query from the database. The syntax is:

update tablename set fieldname = Replace(fieldname, text to replace, replacement text)
Back to Top
Nischint View Drop Down
Groupie
Groupie
Avatar

Joined: 26 August 2002
Location: India
Status: Offline
Points: 62
Post Options Post Options   Thanks (0) Thanks(0)   Quote Nischint Quote  Post ReplyReply Direct Link To This Post Posted: 22 June 2003 at 3:39pm

Blair, your suggestion is great, but I'm looking for a more permanent solution, and I want to be able to make the changes within the database itself.

ljamal, your way works the best. The db itself is quite large, so I can't download it, make the change and reupload it, without getting lots of problems and errors. Is there any way I can create an asp page with this query?? I tried it, but I got it wrong, it just changed all the records to the fieldname for some reason. Here's the sql:

sql = "update tblLinks set strLinks= Replace(strLinks, ../stuff/, ../info/)"

What could be the error??

A better idiot

Jam Like That
Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 22 June 2003 at 3:47pm

sql = "update tblLinks SET strLinks=Replace(strLinks,'../stuff/','../info/')"

If you want to keep stuff and info as a variable then you gotta sep the sql query.



Edited by michael
Back to Top
Nischint View Drop Down
Groupie
Groupie
Avatar

Joined: 26 August 2002
Location: India
Status: Offline
Points: 62
Post Options Post Options   Thanks (0) Thanks(0)   Quote Nischint Quote  Post ReplyReply Direct Link To This Post Posted: 22 June 2003 at 4:03pm
sql = "update tblLinks SET strLinks = Replace(strLinks,'../stuff/','../info/')"

doesn't work. It throws up this error:

Undefined function 'Replace' in expression.

What gives??
A better idiot

Jam Like That
Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.