Error trying to create an array of objects

0

I'm trying to create an array of objects however I'm 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 polish 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();
        }

        }
    
asked by anonymous 21.06.2018 / 02:56

0 answers