samoht Posted September 30, 2009 Share Posted September 30, 2009 Hi, I need a little help writting the correct code for inserting values into a mysql table after querying another. From table tbl_posts I need to SELECT the ID WHERE guid LIKE %timalerts% this returns a query of about 650 rows. I then need to insert into table tbl_term_relationships an object_id that = the ID from the previous query and a term_id of 8 (in this case) I know I'll need to do a loop - but I'm not sure which I should use? WHILE; FOREACH; ?? Please help, Thanks Link to comment https://forums.phpfreaks.com/topic/176116-insert-query-help/ Share on other sites More sharing options...
cunoodle2 Posted September 30, 2009 Share Posted September 30, 2009 Why don't you start by writing out some code (as best as possible) then we will have a better idea of what you are trying to do. You might not need to do a loop as you can insert hundreds of items with a single insert statement. I'll come back on here a bit later to check up and see what I can do to help out. Link to comment https://forums.phpfreaks.com/topic/176116-insert-query-help/#findComment-928005 Share on other sites More sharing options...
greatstar00 Posted October 1, 2009 Share Posted October 1, 2009 if your term_id is same for all, u can use insert select insert tbl_term_relationships select the_ID, 31797411 as term_id from tbl_posts where guid like '%timalerts%' Link to comment https://forums.phpfreaks.com/topic/176116-insert-query-help/#findComment-928163 Share on other sites More sharing options...
redarrow Posted October 1, 2009 Share Posted October 1, 2009 Your best bet is to get the correct info needed, out off the tables that got 650 entry's, then enter them to new table. the only way your do this, is by using a select , and selecting the correct info wanted, for the new table. Link to comment https://forums.phpfreaks.com/topic/176116-insert-query-help/#findComment-928264 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.