0

如果我有这样的表:

ID | Title | Topic      | Summary    
1   |   A   | Technology | ...    
2  |   B   | Health     | ...    
3  |   C   | Sport      | ...

这是我的 CI_Model:

function show($limit, $offset)
    {
        $this->db->select('document.id, document.title, document.summary, document.id_topic AS topic');
        $this->db->from('document');
        $this->db->join('topic', 'topic.id_topic = document.id_topic');
        $this->db->limit($limit, $offset);
        $this->db->order_by('id', 'asc');
        return $this->db->get()->result();
    }

这是我的控制器:

            $docdata = $this->Trainingmodel->show($this->limit, $offset);
        ...
        $this->table->set_heading('ID', 'Title', 'Topic', 'Summary');
        foreach ($docdata as $doc)
        {
            $this->table->add_row($doc->id, $doc->title, $doc->topic, $doc->summary);                                                                                               
        }

显然,该主题显示它的 ID,而不是名称。例如:

ID | Title | Topic      | Summary    
1   |   A   | 1 | ...    
2  |   B   | 2  | ...    
3  |   C   | 3  | ...

我应该怎么办?我想显示主题的名称,而不是主题的 ID。

4

3 回答 3

1
$this->db->select('document.id, document.title, document.summary, topic.topic');
$this->db->from('document');
$this->db->join('topic', 'topic.id = document.id_topic');
于 2013-05-02T02:50:09.097 回答
1

查看您在其他答案中作为评论发布的表格结构,我认为您需要topic.topic在您的select()topic.id = document.id_topic您的join()-

$this->db->select('document.id, document.title, document.summary, topic.topic');
$this->db->from('document');
$this->db->join('topic', 'topic.id = document.id_topic');
于 2013-05-02T03:08:52.377 回答
0

也许是因为这个document.id_topic

$this->db->select('document.id, document.title, document.summary, document.id_topic AS topic');

它应该是类似的东西document.topicdocument.name_topic

于 2013-05-02T02:54:09.183 回答