hello, i have alot of data in table that i cant update each element alone and i want to change one word in the all elements with one query if i have table called "data" , column "column_name", in the "column_name" for example phrase = "http://sitename.com/path/1111.jpg" , phrase = "http://sitename.com/path/2222.jpg" , phrase = "http://sitename.com/path/333.jpg" , ....................... i wanna make the all links http://mysite.com not http://sitename.com and the rest of the paths will stay as it is so can i update one word in the all data in that column ?? thanks
use str_replace() like $text = "http://sitename.com/path/1111.jpg" ; $toreplace = "http://sitename.com"; $yoursite = "urlhere"; $textreplace = str_replace($toreplace, $yoursite, $text);
Use a MySQL Query and update the database directly... UPDATE [table_name] SET [field_name] = REPLACE([field_name],'[string_to_find]','[string_to_replace]'); ... so for example ... UPDATE data SET column_name = REPLACE(column_name,'http://mysite.com','http://sitename.com');
okay i have the table called users and the column name called link link = "http://sitename.com/path/1111.jpg" , where userid = "1" link = "http://sitename.com/path/2222.jpg" , where userid = "2" link = "http://sitename.com/path/333.jpg" , where userid = "3" ,........... alot of data so i executed that query UPDATE `users` SET `link` = Replace( `link`, 'http://sitename.com', 'http://mysite.com' ); and i thought it gonna be like that link = "http://mysite.com/path/1111.jpg" , where userid = "1" link = "http://mysite.com/path/2222.jpg" , where userid = "2" link = "http://mysite.com/path/333.jpg" , where userid = "3" ,........... but it became like that link = "link" , where userid = "1" link = "link" , where userid = "2" link = "link" , where userid = "3" ,...........
thanks guys , i got it the right one is UPDATE `table` SET `column` = Replace( `column`, 'http://sitename.com', 'http://mysite.com' );