Extract php returns Undefined variable on detail page

0

I'm having the following undefined variable error, I'm developing a shopping cart using URl Friendly. Everything was going well until I got the part of returning all the indexes of my database product, I'm using the extract function which in theory was to turn the indexes of my database into variables, however it's not what's happening , it follows the code of my class Url.

public function PegarUrl($url){
     $sql = "SELECT * FROM CADPRO WHERE URL = '$url'";
     $query = sqlsrv_query($this->Conn->Conectar(), $sql) or die( print_r( sqlsrv_errors(), true));
     return $query;    
}

public function UrlAmigavel($url){

        if(isset($_GET['url'])){

            $url = $_GET['url'];
            $pasta = ROOT.DIRECTORY_SEPARATOR;

            if(substr_count($url,'/') > 0){
                $pagina = explode('/', $url);

                if(file_exists($pasta.$pagina[0].'.php')){
                    include_once $pasta.$pagina[0].'.php';

                }else if($this->PegarUrl($pagina[0])){

                    $dadosprod = (array)$this->PegarUrl($pagina[0]);
                    extract($dadosprod);
                    var_dump($dadosprod);
                    include_once $pasta.'detalhe.php';

                }else{

                    include_once $pasta.'error.php';

                }
            }else{
                if(file_exists($pasta.$url.'.php')){

                    include_once $pasta.$url.'.php';

                }if($this->PegarUrl($pasta[0])){

                    $dadosprod = (array)$this->PegarUrl($url);
                    extract($dadosprod);
                    include_once $pasta.'detalhe.php';

                }else{

                    include_once $pasta.'error.php';

                }
            }
        }else{

            include_once 'home.php';

        }    
    }

After doing this on my details page Url is perfect but when I type the indexes of the bank that should now be variable since I used the extract function, they are undefined and I do not understand why.

Example: detail page

echo $Titulo_Produto

returns undefined even the index calling Product_Definition

    
asked by anonymous 18.10.2016 / 15:48

1 answer

2

I was able to resolve, I was missing a fetch_array myself.

public function PegarUrl($url){
        $sql = "SELECT * FROM CADPRO WHERE URL = '$url'";
        $query = sqlsrv_query($this->Conn->Conectar(), $sql) or die( print_r( sqlsrv_errors(), true));
        if($query){
            if($std = sqlsrv_fetch_array($query)){
                return $std;
            }  
        }    
}
    
18.10.2016 / 16:52