Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

180
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda