我知道我的问题是我在控制器 $name 和 $year 中调用变量的位置,我不确定如何将该数组格式化为控制器中的变量。
模型:
function getId($id)
{
$this->db->distinct();
$this->db->select('*');
$this->db->where('id', $id);
$result = $this->db->get('HWC');
return $result->result();
}
function getVariations($name, $year)
{
$this->db->distinct();
$this->db->select('*');
$this->db->where(array('ModelName' => $name, 'Year' => $year));
$variations = $this->db->get('HWC');
if(mysql_num_rows($variations) != 0)
{
return $variations->result();
}
else
{
}
}
控制器:
$this->load->model('testingsearch');
$data['records'] = $this->testingsearch->getId($id);
$name = $records->ModelName;
$year = $records->Year;
$data['variations'] = $this->testingsearch->getVariations($name, $year);
看法:
foreach($variations as $row){
echo $row['name'];
echo $row['color'];
echo $row['Tampo'];
}