错误号码:1054'on子句'中的未知列'Father.id_grandfather'

时间:2013-03-19 02:25:27

标签: php mysql codeigniter

我有一些表格如下:

Grandfather(id_grandfather, nameGrandfather,birthdate) 
Father(id_father, nameFather, id_grandfather, birthdate) 
Son(id_son, nameSon, id_father, birthdate)

我想选择所有数据Son,Father和Grandfather,如下图所示:

Son1    Father 1    grandfather1 
Son2    Father 1    grandfather1
Son3    Father 2    grandfather1 
Son4    Father 3    grandfather2
Son5    Father 4    grandfather2 

所以创建了一个模型(mfamily.php),如下所示:

Class Mfamily extends CI_Model{ 
    function joinFamily(){
        $this->db->select('Son.id_son, Son.nameSon, Son.id_father, Father.id_father, Father.nameFather,Father.id_grandfather,Grandfather.id_grandfather,Grandfather.nameGrandFather'); 
        $this->db->from('Son', 'Father', 'Grandfather');
        $this->db->join('Grandfather', 'GrandFather.id_country = province.id_country');     
        $this->db->join('province','province.id_country = city.id_city');

        return $this->db->get();    
    } 
 }

在控制器cfamily.php中

Class Cfamily extends CI_Controller{    
    $this->load->model(‘Mfamily’);
    $data[‘family’]=$this->Mfamily-> joinFamily();
    $this->load->view(‘vFamily’,$data); 
}

我的观点vFamily.php

<html>
<body>              
    </tr>
    <?php if($family){ ?><?php
        foreach ($family as $row) { ?> 
        <tr>
            <td><?php echo $row->Son.nameSon?></td> 
            <td><?php echo $row->Father.nameFather?></td>
            <td><?php echo $row->Grandfather.nameGrandfather?></td>
        </tr> 
        <?php }?> 
    <?php }else{ ?> 
        <tr>
            <td colspan="3" align="center">Empty</td>
        </tr> 
    <?php } ?> 
</body> 
</html>

当我编译此源时,我收到一条消息错误,如下所示:

Error Number: 1054 Unknown column 'Father.id_grandfather' in 'on clause' 
Filename: C:\xampp\htdocs\family\system\database\DB_driver.php
Line Number: 330 

我的代码中发生了什么?

1 个答案:

答案 0 :(得分:0)

您忘了关闭$this->db->select();。检查一下自己。

$this->db->select('Son.id_son, Son.nameSon, Son.id_father, Father.id_father, Father.nameFather,Father.id_grandfather,Grandfather.id_grandfather,Grandfather.nameGrandFathe);
$this->db->from(Son, 'Father, 'Grandfather');