| Author |
Topic Search Topic Options
|
Nischint
Groupie
Joined: 26 August 2002
Location: India
Status: Offline
Points: 62
|
Post Options
Thanks(0)
Quote Reply
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/???
|
|
|
 |
Mart
Senior Member
Joined: 30 November 2002
Status: Offline
Points: 2304
|
Post Options
Thanks(0)
Quote Reply
Posted: 21 June 2003 at 2:27pm |
|
replace(rs("link"), "stuff", "info") that should help...
|
 |
b_bonnett
Mod Builder Group
Joined: 16 April 2003
Location: New Zealand
Status: Offline
Points: 275
|
Post Options
Thanks(0)
Quote Reply
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
|
|
|
 |
MorningZ
Senior Member
Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
|
Post Options
Thanks(0)
Quote Reply
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
|
 |
ljamal
Mod Builder Group
Joined: 16 April 2003
Status: Offline
Points: 888
|
Post Options
Thanks(0)
Quote Reply
Posted: 22 June 2003 at 10:04am |
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)
|
|
|
 |
Nischint
Groupie
Joined: 26 August 2002
Location: India
Status: Offline
Points: 62
|
Post Options
Thanks(0)
Quote Reply
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??
|
|
|
 |
michael
Senior Member
Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
|
Post Options
Thanks(0)
Quote Reply
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
|
|
|
 |
Nischint
Groupie
Joined: 26 August 2002
Location: India
Status: Offline
Points: 62
|
Post Options
Thanks(0)
Quote Reply
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??
|
|
|
 |