Multidimensional Arrays [message #180409] |
Mon, 11 February 2013 20:00 |
Rita Ferreira
Messages: 4 Registered: February 2013
Karma:
|
Junior Member |
|
|
Hi,
I need some help with multidimensional arrays, if possible.
I have 3 classes, one to acces to DB called config, another called NoticiasController and another called Noticias and the index.php.
On index, I'm creating an object of NoticiasController and calling the method listar().
On NoticiasController I have an object of config and there on config I query the DB like this:
SELECT id, noticia FROM NOTICIAS;
On the config I only have a mysql_query command.
Then on NoticiasController I'm trying to manage the data returned by that query, and here's problem :S
I'm doing something like this:
NoticiasController.php
public function listar()
{
require_once "../config.php";
require_once'/Models/Noticia.php';
$a=new config();
$sql="SELECT id_noticia, corpo_noticia FROM Noticias";
$res=$a->listar($sql);
$e=array();
while ($row = mysql_fetch_assoc($res))
{
$temp=new Noticia($row["id_noticia"],$row["corpo_noticia"]);
$e[]=$temp; <------------ here is the problem
?> <br /> <?php
}
return $e;
}
Noticia.php
(…)
public function __construct($Id_Noticia, $Corpo_Noticia)
{
$this->Id_Noticia = $Id_Noticia;
$this->Corpo_Noticia = $Corpo_Noticia;
}
public function getCorpoNoticia(){
return $this->Id_Noticia;
}
(…)
My goal is to insert on $e every object of Noticia for then send it to index and print the values but when I try to do it I got the error "Fatal error: Call to a member function getCorpoNoticia() on a non-object in /NoticiaController ".
Can you help me? I'm having lots of problems working with arrays and I've tried another ways to do this but I have never reach what I want.
Thanks :)
|
|
|