Quantcast
Channel: Tópicos
Viewing all articles
Browse latest Browse all 14700

Call to a member function getIdAluno() on a non-object

$
0
0
Hey,
preciso de ajuda sobre um bocado de código.
Tenho uma colecção da classe Notas e vou buscar à BD a informação através deste código:

Código :
$this->notas = new Collection();
    $this->carregaArray();
public function carregaArray(){
$link = mysql_connect('localhost:3307', 'root', 'usbw');
$l = mysql_select_db('estagio', $link);
$sql = "Select * From notas";
$result = mysql_query($sql,$link);
while($row = mysql_fetch_assoc($result)){
    $this->notas->addItem($row);
    }
            }

Estou a tentar usar o $this->notas neste método:

Código :
public function procurarNota($idAluno,$idElemento){
            if(!($this->notas->isEmpty())){
                    foreach($this->notas->getAll() as $nota){
                    for ($i = 0; $i <= $this->notas->getLength(); $i++){
                            if($this->notas->getItem($i)->getIdAluno() && $this->notas->getItem($i)->getIdComp() == $idElemento){
                                    return $nota;
                                    }
                            }
                    }
            }
            return 0;
}

Mas da-me este erro:

Código :
Call to a member function getIdAluno() on a non-object in D:\8.5\root\classes\UC.php on line 709

A funçao getItem é definida por:

Código :
private $items = array();
public function getItem($key) {
            if (isset($this->items[$key])) {
                    return $this->items[$key];
            } else {
                    throw new Exception("No match found for $key.");
            }
    }

O que estou a fazer de errado ?
Obrigado !

Viewing all articles
Browse latest Browse all 14700