2014-10-12 60 views
0

我的數據庫中有一個「登錄」和「個人資料」表。根據登錄ID顯示個人資料數據

登錄= [ 'id_login,用戶名,密碼等...']

輪廓= [ 'id_profile,id_login,全名,地址,等...']

模型

function my_model(){ 

    $this->db->select('fullname, address, A.name_table, B.name_text'); 
    $this->db->from('profile'); 
    $this->db->join('A','A.id_table=profile.id_table'); 
    $this->db->join('B','B.id_text=profile.id_text'); 

    $query = $this->db->get(); 
    if ($query->num_rows() > 0) { 
     return $query->row_array(); 
    } 
} 

控制器

function my_controller(){ 

    $data['view_profil']= $this->model->my_model(); 
    $this->tmp->screen('my_view', $data); 
} 

我要問什麼。如何根據登錄ID顯示個人資料數據?如何在我的視圖文件中執行它?感謝您的幫助。

回答

0

您需要獲取已成功登錄的配置文件的ID並將其存儲在會話中,並在查詢(作爲where子句)中將其用於檢索該特定配置文件的記錄。

$this->db->select('fullname, address, A.name_table, B.name_text'); 
$this->db->from('profile'); 
$this->db->where('id', $this->sessoin->userdata('Profile_ID'); 

然後獲取數組並將其顯示在視圖中!

echo $view_profil['fullname']; 
+0

感謝兄弟,我可以在頁面視圖中顯示數據,但是當我在模型中使用命令'where'時,數據無法顯示並顯示錯誤消息。未解決的問題是根據登錄帳戶(登錄表)顯示配置文件表中的配置文件數據。對我有什麼建議嗎?非常感謝你的幫助。 – 2014-10-14 14:25:55

相關問題