[英]How To Get Data by Name Codeigniter
我是 Codeigniter 的初學者 我有桌子
表_a:
我只想創建有關“STEVE”的詳細數據,例如:
但我無法按名稱獲取所有數據。僅按 ID 獲取數據。
My Model 中的最后一個嘗試代碼:
public function detail($id){
$where = array('id' => $id);
$name = 'name', $name;
$data['sales'] = $this->people->detail($where,'table_a')->row();
$data['saless'] = $this->people->getdatabyname($name);
$this->template->display('test/detail',$data);
}
這是我的 Controller:
function detail($where,$table){
return $this->db->get_where($table,$where);
}
function getdatabyname($name){
$this->db->select('*');
$this->db->from('table_a');
$this->db->where('table_a.name', $name);
return $this->db->get()->result();
}
請幫忙
//if you have $id is table_a primary key id then you can get by this:
//controller
function detail($id){
$data=array();
$this->load->model('model_name');
$table_a_data= $this->model_name->get_table_a_by_id($id);
$data['steve']=$this->model_name->get_steve_by_name($table_a_data->name);
$this->template->display('test/detail',$data);
}
//model
function get_table_a_by_id($id){
return $this->db->where('id',$id)->get()->row_array();
}
function get_steve_by_name($name){
return $this->db->where('name',$name)->get()->result_array();
}
//if you don't have id then use join to get data
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.