0
I am trying to create an array of objects but am getting the following error message: Warning: mysql_fetch_object(): supplied argument is not a Valid Mysql result Resource in
Class
class controler {
        private $anuncios = array();
        private $pedidos=   array();
        private $usuarios = array();
}
Inside the class I made a method to pollute the array with objects
public static function getAnuncios()
        {
            include("conexao.php");
            $query="SELECT * FROM tb_anuncio";
        $result = $conexao->query($query)or die( mysql_error());
       print_r($result);
        if(!isset($anuncios))
        {
            while ($anuncio = mysql_fetch_object($result)) //linha a qual o erro é acusado
            {
               // $obj_anuncio = new anuncio($anuncio['cd_anuncio'],$anuncio['nm_titulo'],$anuncio['ds_anuncio'],$anuncio['cd_usuario'],$anuncio['nm_estado'],$anuncio['nm_cidade'],$anuncio['nm_bairro'],$anuncio['nm_categoria']);
                $anuncios[] = $anuncio;
                foreach ($anuncios as $anuncio)
                 {
                  # code...
               print_r($anuncio->cd_anuncio);
              }
                # code...
            }
            return $anuncios;
            die();
        }
        }
What is inside the
$resultin$anuncio = mysql_fetch_object($result)?– Marcelo Shiniti Uchimura
I put a print_r($result); to see what was inside the result and received a correct return from the I believe, the print_r showed the amount of Rows the type and etc.
– Reignomo
Is not
mysqli_xxxinstead ofmysql_xxx?– Marcelo Shiniti Uchimura
That’s what Raccoon was, I didn’t notice when it was time to use, vlw
– Reignomo