-1

我有一些表格如下:

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

我想选择所有数据儿子,父亲和祖父,如下图所示:

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 

我的代码发生了什么?

4

1 回答 1

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');
于 2013-03-19T02:48:49.583 回答