【问题标题】:Codeigniter Extracting Data From Database With FunctionCodeigniter 使用函数从数据库中提取数据
【发布时间】:2013-06-07 21:54:08
【问题描述】:

我必须从我的 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();
}

【问题讨论】:

  • 您遇到什么错误?消息和更多详细信息(行号等)将很有用

标签: php mysql database codeigniter


【解决方案1】:

您只返回最后一个函数结果,您应该通过创建一个 $data 数组来放置两个函数的结果

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

【讨论】:

    【解决方案2】:

    您正在替换变量 $data 中的结果。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 2012-01-29
      • 1970-01-01
      • 2020-04-22
      相关资源
      最近更新 更多