这是我的原始代码:
$ tail -n 2 outputfile
AI9xRoPQ 00:00:00,007
LEAeMTva 00:00:00,005
所以基本上它请求域id为X的域 然后它根据域表中的所有者ID请求所有者的数据。
我不确定在控制器或模型中放入什么 但这是我现在的模特:
$query_domain = $konek->prepare("SELECT * FROM `domain` WHERE `id` = :id");
$query_domain->bindParam(":id", $id);
$query_domain->execute();
$data_domain = $query_domain->fetch();
$query_owner = $konek->query("SELECT * FROM `people` WHERE `id` = $data_domain->ownerid");
$data_owner = $query_owner->fetch();
答案 0 :(得分:0)
在您的(客户)模型中:
public function get_owner_with_domain($domain)
{
$query = $this->db->select('c.*')->
from('client c')->
join('domain d', 'd.ownerid = c.id')->
where('d.name',$domain)->get();
if ($query) {
return $query->row_array();
// Or, ideally return a client if you have a Client model
// return $query->row(0,'Client');
} else {
// log error?
return false;
}
}
在您的控制器中:
public function client($domain) // or whatever your function might be called
{
$this->load->model('Client');
$client = $this->Client->get_owner_with_domain($domain)
// Do something with the client
// var_dump($client);
$view_data['client'] = $client;
$this->load->view('client_info',$view_data);
}
进一步阅读:
答案 1 :(得分:0)
您只需使用一个查询
即可SELECT people.* FROM people, domain WHERE people.id = domain.ownerId AND domain.id = :id