CodeIgniter Forums
ActiveRecords Result using left join in a "recursive" array - 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: ActiveRecords Result using left join in a "recursive" array (/showthread.php?tid=60557)



ActiveRecords Result using left join in a "recursive" array - El Forum - 04-23-2014

[eluser]Unknown[/eluser]
Hi all,

I'm using left join on a request, it list all categories and all products in each category, the problem is that the result is a dispatched array and i want something like below:

$res = [
[
"category_id" => "1",
"name" => "bar",
"products" => [
[
"product_id" => "1",
"name" => "bar_p_1"
],
[
"product_id" => "2",
"name" => "bar_p_2"
]
]
],
[
"category_id" => "2",
"name" => "foo",
"products" => [
[
"product_id" => "1",
"name" => "foo_p1"
]
]
],
[
"category_id" => "3",
"name" => "other",
"products" => [ ]
]
]

Does someone knows how to do that ? Thanks