我知道我的问题是我在Controller $ name和$ year中调用变量的地方,我不知道如何将该数组格式化为Controller中的变量。
型号:
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'];
}
答案 0 :(得分:0)
function getId($id)
{
$this->db->distinct();
$this->db->select('*');
$this->db->where('id', $id);
$result = $this->db->get('HWC');
return $result->result();
}
You are returning object with result() but displaying as array
foreach($variations as $row){
echo $row['name'];
echo $row['color'];
echo $row['Tampo'];
}
像这样改变
return $result->result_array();
现在查看工作正常。在控制器中,你在这里犯了错误
$data['records'] = $this->testingsearch->getId($id);
将其更改为
$records = $this->testingsearch->getId($id);
现在这些说明应该可以正常工作但条件
if($records){
$name = $records->ModelName;
$year = $records->Year;
$data['variations'] = $this->testingsearch->getVariations($name, $year);
}