Getting data from related table in Codeigniter -- translating MySQL query into CI MVC -


i have worked examples few different stackoverflow posts data related tables in ci, haven't been successful in connecting tables in "where" part, , i'd understand how translate mysql query ci mvc.

this mysql query works dctag fields dctags table dctag_id in articles table matches:

$dctagger = $article['dctag_id']; $query = "select `dctitle`, `dctag_id` dctags dctag_id = '$dctagger'"; $query_run = mysql_query($query); 

this code model, controller, , view files:

model -

public function get_article_dctag() { $this->db->select('*') ->from('dctags') ->where('dctag_id', $this->$data['dctag_id']); $query = $this->db->get(); return $query->result_array(); } 

controller -

public function article($slug) { $data['article'] = $this->article_model->get_article($slug); $data['dctag'] = $this->article_model->get_article_dctag(); $this->load->view('templates/header-article', $data); $this->load->view('article', $data); $this->load->view('templates/footer-home'); } 

view -

<?php foreach ($dctag $dctag_item): ?> <title><?php $dctag_item['dctitle']; ?></title> <?php endforeach; ?> 

error - "a php error encountered... severity: notice... message: undefined variable: data...filename: models/article_model.php" (see model code above)

the problem variable $this->... , don't know needs be. explanations/clarification -- in advance!

if dctag_id in $data['article'] use following code

on controller

public function article($slug)  {     $data['article'] = $this->article_model->get_article($slug);     $data['dctag'] = $this->article_model->get_article_dctag($data['article']['dctag_id']);     $this->load->view('templates/header-article', $data);     $this->load->view('article', $data);     $this->load->view('templates/footer-home');  } 

on model

public function get_article_dctag($id) {     $this->db->select('*')              ->from('dctags')              ->where('dctag_id', $id);     $query = $this->db->get();     return $query->result_array();  } 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -