Multiple queries in one model function - 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: Multiple queries in one model function (/showthread.php?tid=28626) Pages:
1
2
|
Multiple queries in one model function - El Forum - 03-17-2010 [eluser]ozskry[/eluser] Hi there, I have a model with this code: Code: function categories() Now, depending on these categories results, I need to execute a second query like: Code: function sub_categories() How can I do that and send the $categories_array and the $sub_categories_array to the view? Thanks, Cary Multiple queries in one model function - El Forum - 03-17-2010 [eluser]xeroblast[/eluser] Code: $blah['categories'] = $categories_array; Multiple queries in one model function - El Forum - 03-17-2010 [eluser]dark_lord[/eluser] I believe this is possible and much easier through sql's JOIN statement and CI has those activerecords for joining two tables. Multiple queries in one model function - El Forum - 03-17-2010 [eluser]ozskry[/eluser] Hi xeroblast and wish_bear, Thx for your quick replies. In fact, I have one table with rows like: article1 - category1 - sub_category1 article2 - category1 - sub_category2 article3 - category1 - sub_category3 article4 - category2 - sub_category4 article5 - category2 - sub_category4 In need to build a menu like: category1 -sub_category1 -sub_category2 -sub_category3 category2 -sub_category4 My first query retrieves the categories and groups them. Then, I need to use these categories to find the sub_categories. I can do that in pure PHP. Don't understand how to do this in CI. Thanks, Cary Multiple queries in one model function - El Forum - 03-18-2010 [eluser]xeroblast[/eluser] tell me how'd you do it in nativePHP and we'll convert it to CI... Multiple queries in one model function - El Forum - 03-18-2010 [eluser]ozskry[/eluser] Hi xeroblast, I found a solution here: How to convert from PHP to MVC in CodeIgniter Following this example, I created a multi-dimensional array and then used the HTML Helper and the ul() function to build the menu. Regards, Cary Multiple queries in one model function - El Forum - 03-18-2010 [eluser]xeroblast[/eluser] good for you... i already know that... i just want to help you convert your queries not mine... anyway, continue reading... Multiple queries in one model function - El Forum - 03-18-2010 [eluser]ozskry[/eluser] Hi again, Thanks for your help. I'm coming back to you because I just realize that I can't add attributes to the <li> tags in the ul() function. Here is my previous native PHP code: Code: $select_categories = "SELECT category FROM ms_artworks.artworks GROUP BY category"; Hope you can help. Regards, Cary Multiple queries in one model function - El Forum - 03-18-2010 [eluser]xeroblast[/eluser] then dont use the ul()... i just loop the <li> with attributes if i needed one... Multiple queries in one model function - El Forum - 03-18-2010 [eluser]ozskry[/eluser] [quote author="xeroblast" date="1268921985"]then dont use the ul()... i just loop the <li> with attributes if i needed one...[/quote] Yes, ok, but how? A loop on the array? |