其中codeIgniter添加了sql查询

时间:2014-02-16 13:35:24

标签: php mysql sql codeigniter

我在模型中的查询' 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数量,tagstag,   tagsraw_tag FROM(tag2arttags)WHERE tag2arttag_id =   tags.tag_id AND tag2artart_id =' 65' GROUP BY tag2arttag_id   ORDER BY id desc

     

文件名:Z:\ home \ blogj.ru \ www \ system \ database \ DB_driver.php

从那时起来了这个请求

  

ORDER BY id desc

0 个答案:

没有答案