-1

以下のような表があります。

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 

私のコードで何が起こっていますか?

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 に答える