Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

181
Visualizações
how do i Select from table with WHERE condition and desc order using query builder function?

I'm trying to select comments in my Comments table. And I want to select them based on a Report Number and in descending order using the codeigniter 3 query builder functions.

I got this code here in my model and if I var_dump it just doesn't work the way I want to. this is the code I have so far:

$this->db->order_by('Date', 'DESC');
$query=$this->db->where("Comments", array('ReportNum' => $report));
$row=$query->result();

This what i get when I var_dump it:

object(CI_DB_mysqli_result)#27 (8) { ["conn_id"]=> object(mysqli)#16 (18) { ["affected_rows"]=> int(5) ["client_info"]=> string(13) "mysqlnd 8.0.9" ["client_version"]=> int(80009) ["connect_errno"]=> int(0) ["connect_error"]=> NULL ["errno"]=> int(0) ["error"]=> string(0) "" ["error_list"]=> array(0) { } ["field_count"]=> int(5) ["host_info"]=> string(25) "Localhost via UNIX socket" ["info"]=> NULL ["insert_id"]=> int(0) ["server_info"]=> string(21) "5.5.5-10.4.20-MariaDB" ["server_version"]=> int(100420) ["sqlstate"]=> string(5) "00000" ["protocol_version"]=> int(10) ["thread_id"]=> int(571) ["warning_count"]=> int(0) } ["result_id"]=> object(mysqli_result)#26 (5) { ["current_field"]=> int(0) ["field_count"]=> int(5) ["lengths"]=> NULL ["num_rows"]=> int(5) ["type"]=> int(0) } ["result_array"]=> array(0) { } ["result_object"]=> array(5) { [0]=> object(stdClass)#28 (5)

^ this comes before the desired array.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You need a get clause to query a table; you can either use:

where() and get():

$this->db->order_by('Date', 'DESC');
$this->db->where( array('ReportNum' => $report));
$query=$this->db->get("Comments");
$row=$query->result();

or get_where():

$this->db->order_by('Date', 'DESC');
$query=$this->db->get_where("Comments", array('ReportNum' => $report));
$row=$query->result();

About CI 3.x query builder.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda