Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2010

    Exclamation SQL/php script to modify article content en masse?

    'Lo there! I've posted about this briefly before, and have a separate question that should finalize all my pending changes. Here goes nothing...

    I'm running Joomla 1.5 and will be changing almost all of my section/category aliases (which directly impacts URLs). For example, I will be changing this:

    to this:

    The reason for this change is to combine multiple categories into one (I currently have about 3x as many categories as necessary, this will help out my organization for future growth).

    I know how to write the .htaccess rewriterule, but my concern is that all the old links in my old articles will be redirected all the time. Aside from permanently leaving the rewriterule in .htaccess, is there any sort of SQL query that I could run to search for the old URL scheme and replace links within articles with the new schema? Or will I have to manually crawl through all of my articles and change the links?

    Additionally... any other input on the idea as a whole is welcome. I can provide more info if necessary.

    Thanks, guys!

  2. #2
    I am not too familiar with Joomla's content storage, but I have to imagine that it stores it's articles in some kind of table. For this, I will assume the table is "jom_articles", and the content in a field called "content". Also, I am not sure of the joomla database name, so I will call it "joomla" here. I am sure you know the real names.

    PHP Code:
    ="localhost"// Host name
    $username="username"// Mysql username
    $password="password"// Mysql password
    $db_name="jom_articles"// Database name
    $tbl_name="joomla"// Table name
    if($_POST['toReplace'] && $_POST['replaceWith'])
    // Connect to server and select databse.
    mysql_connect("$host""$username""$password")or die("cannot conenct to DB");
    mysql_select_db("$db_name")or die("cannot select DB");

    $sql "SELECT * from articles";
    $result mysql_query($sql);
    $article mysql_fetch_object($result))
    $replacedUrls preg_replace($_POST['toReplace'], $_POST['replaceWith'], $article->content);
    $aid $article->id// this is just assigning the unique id of the article to a var for use in a coming sql query. The field may not actually be id, you will need to make sure
    $sql "UPDATE articles SET content = '$replacedUrls' WHERE id = $aid";
    <form method="post" action="./replaceurls.php">
    <table class="centered">
    <tr><td>To be replaced: </td></tr><tr><td><input type="text" name="toReplace" id="toReplace" placeholder="To be replaced" autofocus="autofocus" required="required" /></td></tr>
    <tr><td>Replace with: </td></tr><tr><td><input type="text" name="replaceWith" id="replaceWith" required="required" placeholder="Replace with" /></td></tr>
    <tr><td><input type="submit" name="Submit" value="Update"></td></tr></table>
    Just browse that and adjust where necessary.

Similar Threads

  1. How to modify code from simple JQuery article?
    By lexington in forum Programming Discussion
    Replies: 7
    Last Post: 04-21-2011, 06:24 PM
  2. Grab, Modify and Display Content on Page
    By Hauzer in forum Programming Discussion
    Replies: 0
    Last Post: 06-24-2010, 01:16 PM
  3. Looking for php + mysql expert to modify script
    By datamansystem in forum Employment / Job Offers
    Replies: 10
    Last Post: 11-04-2007, 02:32 PM
  4. [Paying Job] Need PHP/MySQL coder to modify script.
    By Chaps in forum Employment / Job Offers
    Replies: 3
    Last Post: 02-12-2006, 11:40 AM
  5. User can see/modify your root just from PHP script
    By AlexAT in forum Hosting Security and Technology
    Replies: 47
    Last Post: 12-30-2003, 05:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts