2012-07-31 32 views
0

我试图获取数据获取数据使用这个脚本:未定义的属性,同时从MySQL数据库

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; 
    } 
} 

阿卜杜勒得到结果函数:

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 

回答

0

你选择refReligionNameEN,但是在对象引用(ENID)使用refReligionNameID

+0

我修复了它,但它有相同的错误...我使用脚本来获得另一个数据,如:getethnicity,getnationality。如果我删除了种族和民族的功能。 getreligion函数做得很好。我必须做什么... – user1562329 2012-07-31 06:24:57