Php 从MySQL数据库获取数据时未定义属性
我尝试使用以下脚本获取数据:Php 从MySQL数据库获取数据时未定义属性,php,mysql,sql,select,Php,Mysql,Sql,Select,我尝试使用以下脚本获取数据: public function getReligion() { $sql = 'select refReligionId, refReligionNameEN FROM ref_religion group by refReligionNameEN'; $this->selectSql($sql); $results = $this->getResult();
public function getReligion()
{
$sql = 'select refReligionId, refReligionNameEN FROM ref_religion group by refReligionNameEN';
$this->selectSql($sql);
$results = $this->getResult();
$forms = '
<select name="slcReligion" id="slcReligion" style="width: 204px">
<option value="" selected>Select Religion</option>
';
foreach($results as $result)
{
$forms .= '<option value="'.$result->refReligionId.'">'.$result->refReligionNameID.'</option>';
}
$forms .= '</select>';
return $forms;
}
我可以使用这些脚本获取数据
问题是php页面出现以下错误:
Undefined property: stdClass::$refReligionId
Undefined property: stdClass::$refReligionNameID
您正在选择
refReligionNameEN
,但正在对象引用中使用refReligionNameID
(EN
vs.ID
)。我已修复它,但它有相同的错误。。。我正在使用脚本获取另一个数据,如:GetOccidentity,getnationality。如果我删除get Nationality函数。这个功能做得很好。我必须做什么。。。
public function getResult($getArray = false)
{
$encode = json_encode($this->result);
if($getArray == true)
$array = true;
else
$array = false;
if($this->numResults == 1)
$results = '['.$encode.']';
else
$results = $encode;
$result = json_decode($results, $array);
return $result;
}
Undefined property: stdClass::$refReligionId
Undefined property: stdClass::$refReligionNameID