Re: How do I merge 2 tables
http://book.cakephp.org/view/78/Associations-Linking-Models-Together go through this and u ll get an idea On Sun, Aug 23, 2009 at 5:55 PM, simplesi siwalt...@hotmail.com wrote: I'm re-coding a simple helpdesk application and I'd like to merge 2 tables into one. I could probably do this using a raw MySQL query but I'd like to know if it is possible to do it using a one-time controller/view action. My main table is Issues and my associated table is Changes where each issue has many changes. I'd like to loop through each Issue and find all assoicated Change.details and put them into one Issue.alldetails field. Any ideas please? regards Simon -- View this message in context: http://www.nabble.com/How-do-I-merge-2-tables-tp25103063p25103063.html Sent from the CakePHP mailing list archive at Nabble.com. -- Farjad Habib BS 2011 LUMS --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: How do I merge 2 tables
Farjad Habib wrote: http://book.cakephp.org/view/78/Associations-Linking-Models-Together go through this and u ll get an idea AFAICT there's nothing in there to show how loop through all the records in one table and update another table as appropriate :) I tried modifying the foreach ($issues as issue) loop in my index view of Issues and I can extract all associated Change.detail fields using a inner loop of $totaldetail = ''; foreach($issue['Change'] as $subchange) { if (!empty($subchange['detail'])) { $totaldetail = $totaldetail . $subchange['detail']; } }; but I don't seem able to make Issue.alldetails = $totaldetail and save each updated record :( regards Simon -- View this message in context: http://www.nabble.com/How-do-I-merge-2-tables-tp25103063p25103642.html Sent from the CakePHP mailing list archive at Nabble.com. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: How do I merge 2 tables
sory my bad. On Sun, Aug 23, 2009 at 8:08 PM, simplesi siwalt...@hotmail.com wrote: Farjad Habib wrote: http://book.cakephp.org/view/78/Associations-Linking-Models-Together go through this and u ll get an idea AFAICT there's nothing in there to show how loop through all the records in one table and update another table as appropriate :) I tried modifying the foreach ($issues as issue) loop in my index view of Issues and I can extract all associated Change.detail fields using a inner loop of $totaldetail = ''; foreach($issue['Change'] as $subchange) { if (!empty($subchange['detail'])) { $totaldetail = $totaldetail . $subchange['detail']; } }; but I don't seem able to make Issue.alldetails = $totaldetail and save each updated record :( regards Simon -- View this message in context: http://www.nabble.com/How-do-I-merge-2-tables-tp25103063p25103642.html Sent from the CakePHP mailing list archive at Nabble.com. -- Farjad Habib BS 2011 LUMS --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: How do I merge 2 tables
Here are two basic example of how you do it using MySQL insert with a select statement for the values. http://mysql-tips.blogspot.com/2005/04/mysql-insert-select-example.html and the variation where you can trick mysql into doing an update. http://forums.mysql.com/read.php?61,65650,262461#msg-262461 What you would want to do is create a new empty table with the desired fields from both tables. Then do a select joining the two tables and inserting the results into the new table. Using the second method you should be abel to update to oneof the involved tables... but I wouldn't do that myself. good luck. On Aug 23, 4:08 pm, simplesi siwalt...@hotmail.com wrote: Farjad Habib wrote: http://book.cakephp.org/view/78/Associations-Linking-Models-Together go through this and u ll get an idea AFAICT there's nothing in there to show how loop through all the records in one table and update another table as appropriate :) I tried modifying the foreach ($issues as issue) loop in my index view of Issues and I can extract all associated Change.detail fields using a inner loop of $totaldetail = ''; foreach($issue['Change'] as $subchange) { if (!empty($subchange['detail'])) { $totaldetail = $totaldetail . $subchange['detail']; } }; but I don't seem able to make Issue.alldetails = $totaldetail and save each updated record :( regards Simon -- View this message in context:http://www.nabble.com/How-do-I-merge-2-tables-tp25103063p25103642.html Sent from the CakePHP mailing list archive at Nabble.com. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---