Jim R Posted June 9, 2010 Share Posted June 9, 2010 I have a number of values with wp_1_*rest of information*. I want to delete the "_1" from each of those values. Possible? Link to comment https://forums.phpfreaks.com/topic/204254-deleting-partial-information-from-a-table-value/ Share on other sites More sharing options...
PFMaBiSmAd Posted June 9, 2010 Share Posted June 9, 2010 Assuming your data does not contain any occurrences of wp_1_ you should be able to form an UPDATE query using the REPLACE() function that would change all the occurrences of wp_1_ to anything you want - http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_replace Link to comment https://forums.phpfreaks.com/topic/204254-deleting-partial-information-from-a-table-value/#findComment-1069776 Share on other sites More sharing options...
Jim R Posted June 9, 2010 Author Share Posted June 9, 2010 The syntax is a little confusing. Am I using UPDATE, REPLACE or SELECT? Link to comment https://forums.phpfreaks.com/topic/204254-deleting-partial-information-from-a-table-value/#findComment-1069780 Share on other sites More sharing options...
PFMaBiSmAd Posted June 9, 2010 Share Posted June 9, 2010 UPDATE and REPLACE() Link to comment https://forums.phpfreaks.com/topic/204254-deleting-partial-information-from-a-table-value/#findComment-1069781 Share on other sites More sharing options...
Jim R Posted June 9, 2010 Author Share Posted June 9, 2010 Still not catching how it works, just because everywhere I look it says something different. Here is what I tried: UPDATE REPLACE ('meta_key', 'wp_1_', 'wp_') Link to comment https://forums.phpfreaks.com/topic/204254-deleting-partial-information-from-a-table-value/#findComment-1069782 Share on other sites More sharing options...
haku Posted June 9, 2010 Share Posted June 9, 2010 Are you trying to change the column names, or the data inside the table? If it's the column names, you need to user ALTER. If it's the data inside the table, you haven't told the system what table or what column to update. Link to comment https://forums.phpfreaks.com/topic/204254-deleting-partial-information-from-a-table-value/#findComment-1069785 Share on other sites More sharing options...
Jim R Posted June 9, 2010 Author Share Posted June 9, 2010 Data inside the column. I'm trying to make values that start out with wp_1_ and have them just start wp_ Link to comment https://forums.phpfreaks.com/topic/204254-deleting-partial-information-from-a-table-value/#findComment-1069787 Share on other sites More sharing options...
PFMaBiSmAd Posted June 9, 2010 Share Posted June 9, 2010 An UPDATE query looks like - UPDATE your_table SET your_column = new_value You want the new_value to be the REPLACE() function. P.S. Column names are not enclosed in single-quotes as that makes them a string instead of a column name. Link to comment https://forums.phpfreaks.com/topic/204254-deleting-partial-information-from-a-table-value/#findComment-1069788 Share on other sites More sharing options...
Jim R Posted June 9, 2010 Author Share Posted June 9, 2010 UPDATE wp_usermeta SET meta_key = REPLACE (meta_key,"wp_1_","wp_") UPDATE wp_usermeta SET meta_key = REPLACE ('meta_key',"wp_1_","wp_") Either of those? Link to comment https://forums.phpfreaks.com/topic/204254-deleting-partial-information-from-a-table-value/#findComment-1069791 Share on other sites More sharing options...
Jim R Posted June 9, 2010 Author Share Posted June 9, 2010 Because that didn't work. Link to comment https://forums.phpfreaks.com/topic/204254-deleting-partial-information-from-a-table-value/#findComment-1069793 Share on other sites More sharing options...
Jim R Posted June 9, 2010 Author Share Posted June 9, 2010 It worked. I didn't refresh my table. Here is the correct syntax: UPDATE wp_usermeta SET meta_key = REPLACE (meta_key,'wp_1_','wp_') Link to comment https://forums.phpfreaks.com/topic/204254-deleting-partial-information-from-a-table-value/#findComment-1069810 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.