Problems to make a free query with codeigniter

Asked

Viewed 32 times

0

I am here today to ask for the assistance of those who are more experienced in the matter than I am. I have a free query with codeigniter, that of the error in the execution, but when I run it in Workbenth goes right. I’m gonna drop the code and hope somebody can give me a hand.

protected $cms;

// Construção da classe pai
public function __construct(){  
    parent:: __construct();
    $this->cms = $this->load->database('cms', TRUE);
}

// pega os atributos para exibir no carousel
function getCarousel(){

    $this->cms->query('SELECT titulo.post_title, titulo.post_name, anexo.ID, anexo.guid 
                FROM 
                    pt_posts anexo
                inner join pt_posts titulo on titulo.ID = anexo.post_parent
                WHERE 
                    anexo.post_type = "attachment"
                ORDER BY 
                    ID 
                DESC LIMIT 4');     
    $query = $this->cms->get()->result();
    if ($query) {
        return $query;
    }else{
        return false;
    }

inserir a descrição da imagem aqui

1 answer

0

When you use the function query() do not use Codeigniter get() soon after, because query() is already a complete function by itself. Get the result set of your query like this, for example:

$this->cms->query("
    SELECT
        titulo.post_title,
        titulo.post_name,
        anexo.ID,
        anexo.guid 
    FROM 
        pt_posts anexo INNER JOIN pt_posts ON
            titulo on titulo.ID = anexo.post_parent
    WHERE 
        anexo.post_type = 'attachment'
    ORDER BY 
         ID DESC
    LIMIT 4
");    

$result_set = $query->result_array();

// Imprimindo na tela o result set
print_r($result_set);
die();

Browser other questions tagged

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