0

我尝试使用此脚本获取数据:

   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
4

1 回答 1

0

您正在选择refReligionNameEN,但refReligionNameID在对象引用(ENvs. ID)中使用。

于 2012-07-31T06:12:32.533 回答