2017-10-31 8 views
0

私はという人物という名前のテーブルを持っています。このテーブルには、多くの列と1つの列product_idという名前が付けられています。第2表製品にはすべての製品名が含まれています。テーブルテーブルの商品の商品名の製品を持っているとしましょう。私は人のテーブルの行を表示するとき私は彼のの代わりにの代わりに表示したいと思います。データベースからのレコードを表示する[codeigniter]

<?php 
public function person() 
{ 
    $id= $this->uri->segment(3); 
    $query = $this->model_person->get_persons($id); 
    $data['all_persons'] =$query; 
    $this->load->view('admin/view_person', $data); 

} 
?> 

モデルget_person

public function get_persons($id) 
{ 
    $this->db->select("*"); 
    $this->db->from('person'); 
    $this->db->where('id',$id); 
    $query = $this->db->get(); 
    return $query->result(); 
} 

view_person.php

<?php foreach($all_persons as $p) 
{ 
?> 
    <tr> 
     <th >Person name</th> 
     <td ><?=$p->name;?></td> 
    </tr> 
    <tr> 
     <th >Person affectation</th> 
     <td ><?=$p->affectation;?></td> 
    </tr> 
    <tr> 
     <th>Product name</th> 
     <td><?=$p->id_product;?></td> 
     <!--i want to dispay product name found in product table--> 
    </tr> 
<?php 
} 
?> 
+0

のちょうど印刷PRODUCT_NAMEは、私はちょうど人のテーブルの行をつかむモデルを追加した私たちに、データベースの関係とモデルコード –

+0

の鮮明な画像/ explenationを示しています。今私は人のテーブル – Diasline

答えて

1

このような出力を取得するには、モデルにクエリを実行し参加する必要があります。 view_person.phpで

public function get_persons($id) 
    { 
     $this->db->select("*"); 
     $this->db->from('person'); 
     $this->db->join('product', 'product.id= person.product_id'); 
     $this->db->where('person.id',$id); 
     $query = $this->db->get(); 
     return $query->result(); 
    } 

代わりのproduct_id

<tr> 
     <th>Product name</th> 
     <td><?=$p->product_name;?></td> 
     <!--i want to dispay product name found in product table--> 
    </tr> 
+0

の製品名を表示することはできませんなぜ私は参加方法について考えていない!ありがとうございます。 – Diasline

関連する問題