I'am new in codeigniter and php. This is my models:
function getRelated($newsId, $catId){
$this->db->select('a.id, a.category, a.title, a.photo, a.caption, a. summary, a.detail, a.page_views, b.cat_id');
$this->db->from('news as a');
$this->db->order_by("time", "desc");
$this->db->join('news_categories as b', 'a.id = b.news_id');
$this->db->where('a.id <>', $newsId);
$this->db->where('b.cat_id', $catId);
$query = $this->db->get();
echo $this->db->last_query();
return $query->result();
}
this is my controller:
public function detail($id, $catId){
$this->load->model('news_model');
$data['list'] = $this->news_model->get($id);
$data['related'] = $this->news_model->getRelated($id, $catId);
$this->load->view('page_header');
$this->load->view('news_detail', $data);
$this->load->view('page_footer');
}
And this is the result of query in views:
SELECT
a.id,a.category,a.title,a.photo,a.caption,a.summary,a.detail,a.page_views,b.cat_idFROMnewsasaJOINnews_categoriesasbONa.id=b.news_idWHEREa.id<> '2' ANDb.cat_id= 'title%20one%20test1' ORDER BYtimeDESC
As you see above (views), the result of cat_id is title.. Whats wrong with my code?
my view file (news_detail):
<h3>Related News</h3>
<?php
$i = 0;
foreach ($related as $key => $value) {
if (++$i > 3)
break;
?>
<div class="list">
<a class="title" href="news/detail/<?= $value->id . "/" . $value->title ?>"><?= $value->title ?></a>
</div>
<?php
}?>
The category of post is multiple choice. So, every post can have more than one category. What should i do?
Thanks in advance
news_detail.php? thanks - MonkeyZeus$catIdis a string, not an integer. How is your route setup look like? So if you haven't setup any routes, de default should bethe_controller_name/detail/2/3- Iamzozo$idand$cat_id- Vinie