CodeIgniter Forums
Array issue - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Array issue (/showthread.php?tid=14707)



Array issue - El Forum - 01-12-2009

[eluser]sinvos[/eluser]
Trying to change some data that gets returns using $query->result_array()
Code:
Foreach($query->result_array() as $row)
     {
        $row['name'] = '<input type="text" name="name" value="'.$row['name'].'" size="13" />';
     }
     echo $this->table->generate($query);
My understanding should have worked but nothing happens and table populates normally. So i tried a different way
Code:
Foreach($query->result_array() as $row)
     {
       $data[]=$row
       $data['name']='<input type="text" name="name" value="'.$row['name'].'" size="13" />';
     }

  echo $this->table->generate($data);
Now the data is mixed and it only returns 2 rows none of which is header. So whats the proper way of making this happen??
Thanks in advance.


Array issue - El Forum - 01-12-2009

[eluser]cahva[/eluser]
Havent used the table class but you could try the second way like this:
Code:
$data = array();
Foreach($query->result_array() as $row)
{
    $row['name'] = '<input type="text" name="name" value="'.$row['name'].'" size="13" />';
    $data[]=$row
}

echo $this->table->generate($data);
If you dont get the headers(as I think you wont), you can pass the headers where I initialized the $data array.
For examle:
Code:
$data = array( 0 => array('Name','Age','Sex','Email'));



Array issue - El Forum - 01-13-2009

[eluser]xwero[/eluser]
You can always use the set_heading method of the table class


Array issue - El Forum - 01-14-2009

[eluser]sinvos[/eluser]
Thanks cahva that did the trick.