hoverinc Posted January 18, 2011 Share Posted January 18, 2011 Hello guys, please need to search in a table and find specific values in a field and replace it with a value in another field of the same table. certain i will use such mysql_fetch_array($result) Help needed please Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/224844-how-can-i-search-in-a-table-specific-field-value-and-replace-it-with-another/ Share on other sites More sharing options...
Pikachu2000 Posted January 18, 2011 Share Posted January 18, 2011 Can you provide some more details? Will the value be replaced with a value from another field in the same record? From a different record? Quote Link to comment https://forums.phpfreaks.com/topic/224844-how-can-i-search-in-a-table-specific-field-value-and-replace-it-with-another/#findComment-1161361 Share on other sites More sharing options...
hoverinc Posted January 18, 2011 Author Share Posted January 18, 2011 Thanks, yes its a value in the same table's field which is going to replace the found value. Quote Link to comment https://forums.phpfreaks.com/topic/224844-how-can-i-search-in-a-table-specific-field-value-and-replace-it-with-another/#findComment-1161365 Share on other sites More sharing options...
Pikachu2000 Posted January 18, 2011 Share Posted January 18, 2011 Assuming you mean the value is in the same record, you can do it all in a single query like so: UPDATE `table` SET `field1` = `field2` WHERE (some condition exists . . . ) You may want to copy your table and test it on the copied data to verify it does what you want it to do before using it on production data. Quote Link to comment https://forums.phpfreaks.com/topic/224844-how-can-i-search-in-a-table-specific-field-value-and-replace-it-with-another/#findComment-1161380 Share on other sites More sharing options...
hoverinc Posted January 18, 2011 Author Share Posted January 18, 2011 Thanks Pikachu2000 for your reply, but here i have to walk through the whole records and then find the values that will be changed and replace it from the other field of the same table, like for example col1 values to be replaced by values from col2 on certain condition and through the whole records, thus i need to run through foreach or some thing like that. Quote Link to comment https://forums.phpfreaks.com/topic/224844-how-can-i-search-in-a-table-specific-field-value-and-replace-it-with-another/#findComment-1161392 Share on other sites More sharing options...
mikosiko Posted January 18, 2011 Share Posted January 18, 2011 what was provided to you do that. Quote Link to comment https://forums.phpfreaks.com/topic/224844-how-can-i-search-in-a-table-specific-field-value-and-replace-it-with-another/#findComment-1161400 Share on other sites More sharing options...
Pikachu2000 Posted January 18, 2011 Share Posted January 18, 2011 Can you provide some sample data, and describe the conditions? Quote Link to comment https://forums.phpfreaks.com/topic/224844-how-can-i-search-in-a-table-specific-field-value-and-replace-it-with-another/#findComment-1161402 Share on other sites More sharing options...
Muddy_Funster Posted January 19, 2011 Share Posted January 19, 2011 hoverinc, the SQL update statement will run through the entire table and update all records that match your where condition. That's how it works, always. Pikachu gave you the code you need to use. To do it the way that you are thinking about is way too complicated. Look into the SQL more. Quote Link to comment https://forums.phpfreaks.com/topic/224844-how-can-i-search-in-a-table-specific-field-value-and-replace-it-with-another/#findComment-1161693 Share on other sites More sharing options...
hoverinc Posted January 19, 2011 Author Share Posted January 19, 2011 Thanks to all of you guys, i will tru to do using what was suggested to me by all of you, hope everything will go ok, and if not i will refer to your valuable solutions. Quote Link to comment https://forums.phpfreaks.com/topic/224844-how-can-i-search-in-a-table-specific-field-value-and-replace-it-with-another/#findComment-1161788 Share on other sites More sharing options...
Muddy_Funster Posted January 19, 2011 Share Posted January 19, 2011 good luck, I hope it goes well. Quote Link to comment https://forums.phpfreaks.com/topic/224844-how-can-i-search-in-a-table-specific-field-value-and-replace-it-with-another/#findComment-1161799 Share on other sites More sharing options...
hoverinc Posted January 24, 2011 Author Share Posted January 24, 2011 Dear guys Infact we are transfering contents of website to another, so we have 3 tables, one table that have articles in (field X) these article related to images in another table that have 2 fields (ID OF ARTICLE) & (ID OF IMAGE) and the third table contains fields of (IMAGE ID) & (IMAGE NAME) this all were in the previous style of the website, means there are 3 tables, but now we are transferring to JOOMLA, so in joomla we have transferred all articles of the first table that contains the articles of 6000 records, now WE NEED TO ATTACH EVERY IMAGE TO ITS ARTICLE in the first table by adding in the text the <IMG> tags so can read the path. AND IN REALITY I THINK WE HAVE TO COMPARE ID OF IMAGE TO IT'S PROPER ARTICLE SOMETHING LIKE THAT, I NEED YOUR COLLABORATION OF DEMONSTRATING THIS PLEASE OR IDEADS THAT SIMPLIFIES THIS TYPE OFWORK... THANKS Quote Link to comment https://forums.phpfreaks.com/topic/224844-how-can-i-search-in-a-table-specific-field-value-and-replace-it-with-another/#findComment-1164301 Share on other sites More sharing options...
fenway Posted January 26, 2011 Share Posted January 26, 2011 So what are you asking for? Quote Link to comment https://forums.phpfreaks.com/topic/224844-how-can-i-search-in-a-table-specific-field-value-and-replace-it-with-another/#findComment-1165690 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.