CodeIgniter Forums
convert code to CI - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: convert code to CI (/thread-9546.html)



convert code to CI - El Forum - 06-29-2008

[eluser]Mitja B.[/eluser]
Code:
while($row = mysql_fetch_assoc($result))
            {
                $pool['id'][] = $row['pool_id'];
                $pool['date'][] = strtotime($row['pool_date']);
                $pool['question'][] = $row['pool_question'];
                $pool['answerID'][] = $row['answer_id'];
                $pool['answer'][] = $row['answer'];
                //$pool['valid'][] = gmdate("d.m.Y", $row['pool_valid']);
                $pool['valid'][] = date("d.m.Y",$row['pool_valid']);
                $pool['votes'][] = $row['answer_votes'];
                $pool['active'][] = $row['pool_active'];
            }

i want to add this code inside controller that i will use it in view. I try like this.

Code:
foreach ($query->result() as $row)
            {
                $data['id'][] = $row['pool_id'];
                $data['date'][] = $row['pool_date'];

            }

and then i load $data

but i get error of
Fatal error: Cannot use object of type stdClass as array in C:\HTTPSERVER\wwwroot\bewoop\system\application\controllers\admin.php on line 128

how to make this?
Thx


convert code to CI - El Forum - 06-29-2008

[eluser]Seppo[/eluser]
If you want $row to be an array, you should use result_array method. Otherwise, access it as an object ($row->pool_id)


convert code to CI - El Forum - 06-29-2008

[eluser]Mitja B.[/eluser]
thx result_array works like a charm.

regards