Ptreese84 Posted December 14, 2010 Share Posted December 14, 2010 Hello, mysql 5.1.36 php 5.3.0 I searched the forums but im not sure what im looking for. Im trying to copy table columns. Basically each row is setup as: name, id, storeid, a1, a2, a3, a4, b1, b2, b3, b4 i need a way to copy a1 to b1, a2 to b2, a3 to b3, a4 to b4 where storeid = "value" there are multiple users with the same storeid.. so it will need to loop through each one. Im sure this is a noob question and i apologize in advance. I tried "INSERT INTO table (b1, b2, b3, b4) SELECT a1, a2, a3, a4 FROM table WHERE storeid = '$value'"; but that did not work. No errors, just returns '1'. Not sure what else to try. Any help is appreciated. Thx in advance. Quote Link to comment https://forums.phpfreaks.com/topic/221668-help-copying-table-columns/ Share on other sites More sharing options...
jdavidbakr Posted December 14, 2010 Share Posted December 14, 2010 So you're copying the existing value of a1 into b1 and so forth for each row? I think this may be what you are looking for: update table set b1 = a1, b2 = a2, b3 = a3, b4 = a4 where store_id = '$value' Quote Link to comment https://forums.phpfreaks.com/topic/221668-help-copying-table-columns/#findComment-1147333 Share on other sites More sharing options...
Ptreese84 Posted December 15, 2010 Author Share Posted December 15, 2010 I tried that before and again just now. update table set b1 = a1, b2 = a2, b3 = a3, b4 = a4 where store_id = '$value' Doesnt change the database at all. It returns 1 like the other. Quote Link to comment https://forums.phpfreaks.com/topic/221668-help-copying-table-columns/#findComment-1147459 Share on other sites More sharing options...
jdavidbakr Posted December 15, 2010 Share Posted December 15, 2010 Will that automatically do all the rows that storeid = value or do i need to put in some kind of loop? It will do every row that matches the condition in one statement. Quote Link to comment https://forums.phpfreaks.com/topic/221668-help-copying-table-columns/#findComment-1147460 Share on other sites More sharing options...
Ptreese84 Posted December 15, 2010 Author Share Posted December 15, 2010 Ok.. Got it working.. My storeid variable wasnt getting set correctly.. Ty for your help. Quote Link to comment https://forums.phpfreaks.com/topic/221668-help-copying-table-columns/#findComment-1147462 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.