我在模型中的查询' news_model'
function get_tags($art_id) {
$query = $this->db
->select('COUNT(tag2art.tag_id) AS quantity, tags.tag, tags.raw_tag')
->from('tag2art, tags')
->where('tag2art.tag_id = tags.tag_id')
->where('tag2art.art_id =', $art_id)
->group_by('tag2art.tag_id')
->get();
if ($query->num_rows() > 0) {
$rows = $query->result();
$query->free_result();
return $rows;
} else {
return FALSE;
}
}
我使用此型号的控制器
class News extends MY_Controller {
public function __construct() {
parent::__construct();
$this->load->model('news_model');
$this->load->model('articles_on_menu_model');
}
public function index() {
$data['news'] = $this->news_model->get_news();
if (empty($data)) {
show_404();
}
foreach ($data['news'] as $key => $tags_news) {
$data['news'][$key]['tags'] = $this->tagcloud($tags_news['news_id']);
}
// this load other view
}
public function tagcloud($art_id) {
$tags = $this->news_model->get_tags($art_id);
if (!$tags) {
return;
}
foreach ($tags as $tag) {
$data['tags'][] = array($tag->quantity, $tag->tag, $tag->raw_tag);
}
return $data['tags'];
}
}
然后我打开site.com/news并获取sql错误
错误号码:1054
未知列' id'在'订单条款'
SELECT COUNT(tag2art.tag_id)AS数量,
tags
。tag
,tags
。raw_tag
FROM(tag2art
,tags
)WHEREtag2art
。tag_id
= tags.tag_id ANDtag2art
。art_id
=' 65' GROUP BYtag2art
。tag_id
ORDER BYid
desc文件名:Z:\ home \ blogj.ru \ www \ system \ database \ DB_driver.php
从那时起来了这个请求
ORDER BY
id
desc