Jump to content

Updating Mass Entrys in DB


Exoon

Recommended Posts

Hello,

 

Im using a wordpress blog which has links to filesonic i want to be able to mass update all the links to another host, Ive made a script that will do it for a single link but i can't think how to get it to do it for more than 1 link in the post.

 

sometimes there are files like 1211.part1.rar 1211.part2.rar, It updates the part1 fine but dosen't update part 2. Any ideas how i can alter my script to replace the part2 files aswell?

 

<?php

if($_POST[newlinks]) {
$query = "SELECT * FROM wp_posts WHERE post_status = 'publish'";
$result = mysql_query($query);
while($row=mysql_fetch_assoc($result)) {

$find = $row['post_content'];

  preg_match("/http:\/\/www.filesonic.com\/file\/(.*?)\/(.*?).rar/", $find, $matches);
  
    $newlinks = preg_split('~\s+~s', $_POST['newlinks']);
      rtrim($newlinks, "\n\t\r");
    
    foreach ($newlinks as $newlink) {
      $new_number = explode('/', $newlink);
      $new_number = end($new_number);
      $new_number = str_replace(".rar", "", "$new_number");


      if($matches[2] == $new_number && isset($newlink) && strlen($newlink) > 1) {
         $newsql = preg_replace("/http:\/\/www.filesonic.com\/file\/(.*?)\/(.*?).rar/", $newlink, $find);
            $updatesql = "UPDATE wp_posts SET post_content = '$newsql' WHERE ID = '$row[iD]'";
            if(mysql_query($updatesql) or die(mysql_error())) {
              echo "Success! Replaced http://www.filesonic.com/".$matches[1]."/".$matches[2].".rar with $newlink ID: $row[iD]<br />";
           }
       }
    }

}

} else {
echo "<form method=\"POST\" action=\"update-links.php\">";
echo "<br /> <strong>Enter the new links to try and replace old ones</strong> <br />";
echo "<textarea rows=\"16\" name=\"newlinks\" cols=\"84\"></textarea>";
echo "<input type=\"submit\" value=\"Submit\" name=\B1\">";
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.