[eluser]Smy[/eluser]
controller: news.php
Code:
function index()
{
$this->load->model('NewsModel','newsObj');
$result['news'] = $this->newsObj->getNews(); // function to retrieve the news
$this->load->view('news', $result);
}
Model : newsModel.php
Code:
function getNews(){
$sql="SELECT * FROM tb_news";
$result = $this->db->query($sql);
$res=$result->result();
return $res;
}
function getAttachment($newsID){
$sql="SELECT * FROM tb_attachment where newsId = $newsID";
$result = $this->db->query($sql);
$res=$result->result();
return $res;
}
view: news.php
Code:
echo meta('Content-type', 'text/html; charset=utf-8', 'equiv');
foreach ($news as $row)
{
echo $row->chvNewsTitle;
echo br(1);
}
If i need to display the attachment along with the news Title, how can i call the model getAttachment($row->newsID) from my view