我尝试使用此脚本获取数据:
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;
}
我有父类函数:
public function selectSql($sql)
{
$query = @mysql_query($sql);
if($query)
{
$this->numResults = mysql_num_rows($query);
for($i = 0; $i < $this->numResults; $i++)
{
$r = mysql_fetch_array($query);
$key = array_keys($r);
for($x = 0; $x < count($key); $x++)
{
// Sanitizes keys so only alphavalues are allowed
if(!is_int($key[$x]))
{
if(mysql_num_rows($query) > 1)
$this->result[$i][$key[$x]] = $r[$key[$x]];
else if(mysql_num_rows($query) < 1)
$this->result = null;
else
$this->result[$key[$x]] = $r[$key[$x]];
}
}
}
return true;
}
else
{
return false;
}
}
abd 获取结果函数:
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;
}
我可以使用这些脚本获取数据,
问题是 php 页面出现了这些错误:
Undefined property: stdClass::$refReligionId
Undefined property: stdClass::$refReligionNameID