New to Joins and codeigniter - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: New to Joins and codeigniter (/showthread.php?tid=22219) |
New to Joins and codeigniter - El Forum - 09-01-2009 [eluser]liam1412[/eluser] I am new to joins; I have always coded the clumsy way with loads of queries, and using MVC this isn't so easy without having loads of code in your view. I have 3 tables categories forums posts What I need is a multi dimensional array that would hold a list of categories and then within each category a list of forums that reside in that category and then within each forum, a post count/thread count. With my old procedural way I can easy acheive what I want without using arrays, but with MVC I am struggling. can anyone help me out. Thanks from a newb to OOP/Mvc/COdeigniter all at once :-) New to Joins and codeigniter - El Forum - 09-01-2009 [eluser]alboyd[/eluser] This isn't a question about MVC - simply create your query no? Code: SELECT cats.category_name, f.forum_name, COUNT(p.post_id) FROM categories cats Obviously I have just completely made up what the field names would be but this would be the kinda idea of what you want isn't it? New to Joins and codeigniter - El Forum - 09-01-2009 [eluser]jedd[/eluser] First, post your schema rather than just your table names. [quote author="liam1412" date="1251864552"] What I need is a multi dimensional array that would hold a list of categories and then within each category a list of forums that reside in that category and then within each forum, a post count/thread count. With my old procedural way I can easy acheive what I want without using arrays, but with MVC I am struggling. [/quote] I'd be fascinated to see how you juggled such hierarchical information absent a single array - can you post your extant code for pulling these data in? New to Joins and codeigniter - El Forum - 09-01-2009 [eluser]liam1412[/eluser] Here are the tables as requested. forums forum_id forum_name category_id display_rank forum_categories category_id category_name category_text display_rank forum_posts post_id post_title post_text forum_id response_to time_posted New to Joins and codeigniter - El Forum - 09-01-2009 [eluser]alboyd[/eluser] [quote author="liam1412" date="1251885338"]Here are the tables as requested. forums forum_id forum_name category_id display_rank forum_categories category_id category_name category_text display_rank forum_posts post_id post_title post_text forum_id response_to time_posted[/quote] wow looks like my query would work straight out of the box for that schema So was that helpful or totally not what you were asking? New to Joins and codeigniter - El Forum - 09-01-2009 [eluser]liam1412[/eluser] No it was exactly what I wanted, I modified it slightly to fit my schema but I get an empty result set, apart from all the other bumf codeign gives. Code: $data['result'] = $this->db->query(' Gives Code: object(CI_DB_mysql_result)#12 (7) { New to Joins and codeigniter - El Forum - 09-01-2009 [eluser]alboyd[/eluser] hey mate - break out the query in a query window in like Yog or whatever you use and figure it out from there. You might need to change the join directions etc? New to Joins and codeigniter - El Forum - 09-01-2009 [eluser]liam1412[/eluser] I took out the posts bit but that doesn't seem like I would be able to use that in an easy way. It gives Code: object(CI_DB_mysql_result)#12 (7) { I had another crud class where you could declare a relationship and it would bring this sort of result. Code: Array With this I could use a foreach loop to get the categories, then within that foreach I could use a foreach to get the forums with that category. Thanks for looking New to Joins and codeigniter - El Forum - 09-02-2009 [eluser]garycocs[/eluser] Hi Lads, Sorry to thread hop here, I'm kinda new to the join queries as well and I was just wondering how you would write an Active Record query that lets say: Got the information from one table and the averages of a number of rows from another table? |