我有以下模型函數,我想知道如何改進它,並在需要時拉出需要的$row
,這樣我就不會收到PHP錯誤。查詢改進:foreach
如何,我拉着所需的數據:
$data['companyName'] = $this->core_model->companyDetails('coreCompanyName');
錯誤:
Undefined property: stdClass::$coreContactName
Undefined property: stdClass::$coreContactEmail
型號:
function companyDetails()
{
$this->db->select('coreCompanyName, coreContactName, coreContactEmail');
$this->db->from('core');
$whereData = array('coreCompanyName' => $companyName, 'coreContactName' => $companyContactName, 'coreContactEmail' => $companyContactEmail);
$this->db->where($whereData);
$query = $this->db->get();
$result = '';
if ($query->num_rows() > 0)
{
foreach ($query->result() as $row)
{
$result .= $row->coreCompanyName;
$result .= $row->coreContactName;
$result .= $row->coreContactEmail;
}
}
return $result;
}
在foreach之後,'$ row'的'print_r'給你什麼? – 2012-02-18 03:56:39