Error while trying to create an object array

Asked

Viewed 32 times

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 $result in $anuncio = mysql_fetch_object($result)?

  • 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.

  • Is not mysqli_xxx instead of mysql_xxx?

  • That’s what Raccoon was, I didn’t notice when it was time to use, vlw

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.