Codeigniter用函数从数据库中提取数据

时间:2013-06-07 21:54:08

标签: php mysql database codeigniter

我必须从我的mysql数据库中提取两条独立的信息。我很难通过写作的功能来弄清楚如何提取两组不同的信息。我试图找出解决方案,但我没有得到它。下面是我到目前为止的语法。我的目标是让所有函数(getPrice和getOtherPrice)都在同一个函数中运行。如果我//一个,另一个工作。如果两者都有效,那么只有一个正在运行。你们将如何纠正这个问题,你认为我做错了什么?谢谢大家。

function getJoinInformation($year,$make,$model)
{
$data = $this->getPrice($year,$make,$model);
$data = $this->getOtherPrice($year,$make,$model);
return $data;    
}

function getPrice($year,$make,$model)
{
 $this->db->select('*');
 $this->db->from('tbl_car_description d');
 $this->db->join('tbl_car_prices p', 'd.id = p.cardescription_id');
 $this->db->where('d.year', $year);
 $this->db->where('d.make', $make);
 $this->db->where('d.model', $model);
 $query = $this->db->get();
 return $query->result();
}

function getOtherPrice($year,$make,$model)
{
 $this->db->select('*');
 $this->db->from('tbl_car_description d');
 $this->db->where('d.year', $year);
 $this->db->where('d.make', $make);
 $this->db->where('d.model', $model);
 $query = $this->db->get();
 return $query->result();
}

2 个答案:

答案 0 :(得分:0)

您正在替换变量$ data。

中的结果
$data = $this->getPrice($year,$make,$model);
$data = $this->getOtherPrice($year,$make,$odel);

$ data将始终只包含最后一个函数的结果。

答案 1 :(得分:0)

您只返回最后一个函数结果,您应该通过创建$data

数组来放置两个函数的结果
function getJoinInformation($year,$make,$model)
{
$data['getPrice'] = $this->getPrice($year,$make,$model);
$data['getOtherPrice'] = $this->getOtherPrice($year,$make,$model);
return $data;    
}