database - Encountering a PHP error "Illegal string offset" in fetching data using codeigniter -


so, experimenting on web app. want displaying user's list of posts in timeline matching logged-in user's id id on 'posts' database.

here's model

public function load_posts($user_id) {     $this->db->where("user_id",$user_id);     $query=$this->db->get('posts');      if ($query->num_rows()>0)     {         foreach($query->result() $rows)         {             $haha = array(                 'post_id'   => $rows->id,                 'title'     => $rows->title,                 'artist'    => $rows->artist,                 'album'     => $rows->album,                 'caption'   => $rows->caption,             );         }            return $haha;     }     return array(); } 

my controller

public function welcome() {     $data['title']= 'welcome';      $user_id=$this->session->userdata('user_id');     $haha['hah'] = $this->user_model->load_posts($user_id);      $this->load->view('header_view',$data);     $this->load->view('welcome_view.php', $haha);     $this->load->view('footer_view',$data); } 

and view

<div class="timeline">     <div class="boxes">         <table>         <?php             foreach($hah $rows):         ?>         <tr>             <td><?php echo $rows['title']; ?></td>             <td><?php echo $rows['artist']; ?></td>             <td><?php echo $rows['album']; ?></td>             <td><?php echo $rows['caption']; ?></td>         </tr>         <?php             endforeach;         ?>         </table>     </div> </div> 

with codes, 4 rows of these errors

a php error encountered  severity: warning  message: illegal string offset 'title'  filename: views/welcome_view.php  line number: 25  2    php error encountered  severity: warning  message: illegal string offset 'artist'  filename: views/welcome_view.php  line number: 26  2    php error encountered  severity: warning  message: illegal string offset 'album'  filename: views/welcome_view.php  line number: 27  2    php error encountered  severity: warning  message: illegal string offset 'caption'  filename: views/welcome_view.php  line number: 28  2 

and in case needed, 'posts' table

create table if not exists `posts` ( `id` int(11) not null, `title` varchar(255) not null, `artist` varchar(255) not null, `album` varchar(255) not null, `cover` varchar(30) not null, `caption` text not null, `user_id` int(11) not null, `posttime` timestamp not null default current_timestamp on update current_timestamp ) 

any appreciated!

your returned array of results not using keys expect them appear, yet trying access them. best way familiar return structures in codeigniter read documentation or if you're more 'hands-dirty' type myself, put var_dump($haha) in model right before return statement.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -