blazingt Posted February 5, 2010 Share Posted February 5, 2010 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? Quote Link to comment Share on other sites More sharing options...
mapleleaf Posted February 5, 2010 Share Posted February 5, 2010 you need a $row = mysql_fetch_array($result); in there for starters Quote Link to comment Share on other sites More sharing options...
blazingt Posted February 5, 2010 Author Share Posted February 5, 2010 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"); } } ?> Quote Link to comment Share on other sites More sharing options...
blazingt Posted February 5, 2010 Author Share Posted February 5, 2010 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"; ?> Quote Link to comment Share on other sites More sharing options...
mapleleaf Posted February 7, 2010 Share Posted February 7, 2010 if (!$tpost) { might work better if it was if ($tpost) { assuming i understood what you are trying to do Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.