Jump to content

database record update


vbnullchar

Recommended Posts

Basic idea

 

<?php
//SQL stuf
$SQL = "SELECT field  FROM table WHERE field LIKE %http://site1/directory%;";

$updateSQL = "";
//loop each record
while($row = mysql_query($SQL))
{
$ID = $row['id'];
$newData = preg_replace('%(.*)(?:http://site1/directory)(.*)%i', '$1http://site2/directory$2', $Data);
$updateSQL .= "UPDATE table SET field = '$newData' WHERE ID = $ID;";
}
mysql_query($updateSQL);
?>

Link to comment
Share on other sites

Basic idea

 

<?php
//SQL stuf
$SQL = "SELECT field  FROM table WHERE field LIKE %http://site1/directory%;";

$updateSQL = "";
//loop each record
while($row = mysql_query($SQL))
{
$ID = $row['id'];
$newData = preg_replace('%(.*)(?:http://site1/directory)(.*)%i', '$1http://site2/directory$2', $Data);
$updateSQL .= "UPDATE table SET field = '$newData' WHERE ID = $ID;";
}
mysql_query($updateSQL);
?>

 

this looks good, i'll try it.. thanks alot

Link to comment
Share on other sites

just went a read a little more of this thread...

 

YOU can do all this in one query

 

$qry = "UPDATE `tablename` SET `field` = REPLACE(`field`,'http://site/directory','http://site2/directory')";

$qry = mysql_query($qry);

 

Better still just run

 

UPDATE `tablename` SET `field` = REPLACE(`field`,'http://site/directory','http://site2/directory') in your phpmyadmin...

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.