SQL - Codeigniter - Returns only one record

Asked

Viewed 541 times

1

Gentlemen, I have the following function:

// Busca Simples
public function buscando(){

    // pesquisar_palavra, idCategoria, idSubCategoria       

        if($this->input->post('pesquisar_palavra')){ 
            $this->db->like('noticia.titulo', $this->input->post('pesquisar_palavra')); 
        }   
        if($this->input->post('idCategoria')){ 
            $this->db->select('noticia.*, categoria.categoria');
            $this->db->join('categoria', "categoria.id=noticia.id"); 
            $this->db->where('categoria.id', $this->input->post('idCategoria'));
        }
        if($this->input->post('idSubCategoria')){ 
            $this->db->where('noticia.id_categoria', $this->input->post('idSubCategoria')); 
        }

    $this->db->where('noticia.ativo', 1);
    $this->db->order_by('noticia.data', 'DESC');
    $this->db->order_by('noticia.id', 'DESC');
    $consulta = $this->db->get('noticia')->result();

    echo "<pre>";
    print_r($consulta);
    echo "</pre>";
    die();
}

His return is just a record, not 3, as shown in the following database:

inserir a descrição da imagem aqui

This is the Search Post criterion.

Array
(
    [pesquisar_palavra] => 
    [idCategoria] => 1
    [idSubCategoria] => 5
)
  • Hi, could give more information regarding the problem, as the structure of the tables.

1 answer

4


Change the line:

$consulta = $this->db->get('noticia')->result();

For:

$consulta = $this->db->get('noticia');

Browser other questions tagged

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