Note that there are some explanatory texts on larger screens.

plurals
  1. POReturning and using multidimensional array of records from database in CodeIgniter 2.0
    text
    copied!<p>Hey guys ! Well I was trying out codeigniter but it seems to me that I have made some kind of mess while trying to retrieve and display the data from the tables here is the code snippet.</p> <p>I want to retrieve all the articles stored in my article table along with that I need to pull out all the tags associated with each article from the relationship table and the tag table called articleTagRelation and tags respectively</p> <pre> Table structure : Article table : articleID, articleContent, date Tags table : tagID, tagName articleTagRelation : aricleID,tagID {Combination of both is my primary key} </pre> <pre> CI model : article_model.php public function getAllTags($postId){ $this->db->select('articleTagRelation.tagId as tagId, articleTagRelation.postId as postId, article.tagName as tagName,'); $this->db->from('articleTagRelation'); $this->db->join('Tags','Tags.tagId = articleTagRelation.tagId'); $this->db->where('ArticleTagRelation.articleId',$postId); $qTag = $this->db->get(); if($qTag->num_rows() > 0){ foreach ($qTag->result() as $tag) { return $tag; } } } public function getAllArticles(){ $this->db->select('*'); $this->db->from('Article'); $this->db->order_by('date','desc'); $query=$this->db->get(); if($query->num_rows()>0){ foreach ($query->result() as $row) { $data['row'] = $row; $data['articletags'] = $this->getAllTags($row->articleId); // I'm trying to get get a array of all the associate tags. $post=array($data['row'],$data['articletags']); } }else{ echo 'nothing found !'; } return $post; } </pre> <pre> my controller file article.php I'm calling this function in the index function $data['rows'] = $this->blog_model->getAllArticles(); and then loading the view by passing the data array </pre> <pre> now the part where things get messy in my view echo $r->articleId // works fine echo $r->articletags->tagId //gives me a error message Can any one help me out in printing those tagIds </pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload