i need help, how to merge ... newbie :) - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: i need help, how to merge ... newbie :) (/showthread.php?tid=10680) |
i need help, how to merge ... newbie :) - El Forum - 08-08-2008 [eluser]amrnt[/eluser] how to merge 2 tables the first table called users and has id,name, and some other columns, the other table is the actions, and has id, user_id, action ... so user has many actions... how to get merge with less number of sql queries? i need help, how to merge ... newbie :) - El Forum - 08-08-2008 [eluser]Pascal Kriete[/eluser] Do you want to merge them physically - i.e. make a new table with all the data. Or do you want to select from both tables, joining them on the user_id ? i need help, how to merge ... newbie :) - El Forum - 08-08-2008 [eluser]amrnt[/eluser] joining them. i need help, how to merge ... newbie :) - El Forum - 08-08-2008 [eluser]amrnt[/eluser] i'm now reading about activerecords class, is there like rails joining ; has_many, belongs_to, has_and_belongs_to_many i need help, how to merge ... newbie :) - El Forum - 08-08-2008 [eluser]Pascal Kriete[/eluser] You need to add a where statement to your query: Code: $this->db->select('users.*, actions.action'); Let us know how that goes. i need help, how to merge ... newbie :) - El Forum - 08-08-2008 [eluser]Pascal Kriete[/eluser] Whoops, missed your last reply. There are no orm functions, but if you search the forums for 'orm' there are a few libraries out there. i need help, how to merge ... newbie :) - El Forum - 08-08-2008 [eluser]amrnt[/eluser] thanks, but what i need is : User_model Code: function get_name($id = null) View Code: foreach($actions as $action): i need help, how to merge ... newbie :) - El Forum - 08-08-2008 [eluser]amrnt[/eluser] i want to be sth like Code: echo $action->User->name; i need help, how to merge ... newbie :) - El Forum - 08-08-2008 [eluser]hvalente13[/eluser] Hi, What you want to do is like to put a pulley to make things go faster! Active record it's capable of assist you to make what you want to do! And what I understood is that you want an header with user info and below the user actions! 1. Simple: Make two queries! I've read somewhere that separate queries give faster results! Give it a try. 2. Complex: Subqueries! This way you have to make sql string by hand and then you can retrieve it by: Code: $sql_strin = "SELECT * FROM ..." // you know what you want to do This way the results will be all in the same row. Hope this helpS i need help, how to merge ... newbie :) - El Forum - 08-08-2008 [eluser]amrnt[/eluser] [quote author="hvalente13" date="1218236624"]..... 1. Simple: Make two queries! I've read somewhere that separate queries give faster results! Give it a try. ....[/quote] Thanks, i'm using now separate queries |