• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
convert code to CI

#1
[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

#2
[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)

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

regards


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.