Jump to content

replacing info from DB


blazingt

Recommended Posts

I have this so far:

<?php
$con = mysql_connect("localhost","peter","123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
$result = mysql_query("SELECT * FROM phpbb_posts");
if(!$result) die("Query Failed.");

//is this right?
$newrow = $row['post_text'];
$newrow = preg_replace('/(class="postlink")/','class="postlink" rel="nofollow" target="_blank"',$newrow);
$result = mysql_query("UPDATE phpbb_posts SET post_text=$newrow");
?>

So for each row in phpbb_posts it will get the text, change the link and then it will store it in newrow. From there it will now update the row with the replaced url.

 

post_id is the primary key, it starts from 1 and goes up about 3000, but not all the numbers are being used. For example, there's information on post_id 2 and post_id 4 but post_id 3 doesn't exists. I know this can become a problem.

How does this look? I know it's probably wrong.

I want to be able to check all posts in my forum and replace a certain string with a new one. How can this be done?

Link to comment
Share on other sites

How does this looks now?

 

<?php
$con = mysql_connect("localhost","peter","123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

for ( $counter = 1; $counter <= 5000; $counter += 1)
{

$result = mysql_query("SELECT * FROM phpbb_posts WHERE post_id=$counter");
if(!$result) die("Query Failed.");

$row = mysql_fetch_array($result);
if(mysql_num_rows($row))
   {
      $newrow = $row['post_text'];
      $newrow = preg_replace('/(class="postlink")/','class="postlink" rel="nofollow" target="_blank"',$newrow);
      $result = mysql_query("UPDATE phpbb_posts SET post_text=$newrow");
   }

}
?>

Link to comment
Share on other sites

Since I can't edit my post. Here's the update. I get no errors, but nothing in my db gets updated :(

<?php
$con = mysql_connect("localhost","traffic_ytf","gu~pxPxU?1gs");
mysql_select_db("traffic_tbb");

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

for ( $counter = 1; $counter <= 5000; $counter += 1)
{

$result = mysql_query("SELECT * FROM phpbb_posts WHERE post_id=$counter");
if(!$result) die("Query Failed.");

$row = mysql_fetch_array($result);
      $tpost = $row['post_text'];
      if (!$tpost) {
      $tpost = preg_replace('/(class="postlink" href=)/','rel="nofollow" target="_blank" class="postlink" href=',$tpost);
      $result = mysql_query("UPDATE phpbb_posts SET post_text=$tpost");}
}
echo "all done";
?>

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.