I use pivot to select some record(s) from my table. This is the query:
$data['master'] = $this->db->query("select * from
(
select row, c.Nilai,b.Fullname,a.KodePenilaian,d.Description from penilaian_header a
left join employee b on a.Nip = b.Nip
left join outlet d on a.Outlet = d.OutletCode
left join (select ROW_NUMBER() OVER(PARTITION BY KodePenilaianH ORDER BY idPenilaiand DESC) AS Row, Nilai,KodePenilaianH from penilaian_Detail
) c on a.KodePenilaian = c.KodePenilaianH where a.Outlet like '%$outlet%' and Periode like '%$periode%'
) nilai
pivot
(
sum(nilai)
for row in ([1],[2],[3],[4],[5])
) piv;")->result();
And this the result when I run it via MS SQL Management Tools
now, my problem is to retrieve these [1],[2],[3],[4],[5]
values. When I do this:
echo "<pre>";print_r($data['master']);
die();
I only get this:
Array
(
[0] => stdClass Object
(
[Fullname] => maya kristiana
[KodePenilaian] => PE0000001
[Description] => KIOS ATRIUM3
)
[1] => stdClass Object
(
[Fullname] => SHELVIA GITA PUTRI
[KodePenilaian] => PE0000002
[Description] => KIOS ATRIUM3
)
)
Update: I found the solution, thanks to @Alex Tartan (see accepted answer below):
I simply changed my ->result()
to ->result_array();
and the result is now as desired: