Welcome Guest, Not a member yet? Register   Sign In
orderBy not sorting results

(This post was last modified: 10-06-2018, 06:24 AM by unodepiera.)

(10-05-2018, 07:54 PM)pkMyt1 Wrote: First, you folks are amazing.  Thank you for the tremendous effort you have put into CI4.
I am testing CI4 on a LIMS that I wrote way back for CI2.  I am trying to get sorted results from one of the tables.  I think I am doing it correctly but it is just as likely there is something here I am not understanding.  I have a table with an auto incremented ID and a Cell_Name column.  I am simply trying to do a select all and retrieve the data sorted on the cell name column.  

   $builder = $this->db->table('cell_lines');
       ->orderBy('Cell_Line', 'asc');

   echo $builder->getCompiledSelect(false);
   $query = $builder->get();
   $temp_result = array();

   foreach ( $query->getResult('array') as $row )
$temp_result[] = array(
'ID'            => $row['CellID'],
'Cell_Name'     => $row['Cell_Name'],
'idCell_Type'   => $row['idCell_Type'],
'idGenotype'    => $row['idGenotype'],
'idBasel_Media' => $row['idBasel_Media'],

   return $temp_result;

The generated sql is
                         SELECT * FROM `cell_lines` ORDER BY `Cell_Line` ASC
however I think the order by part is being dropped.

Any suggestions?

Sorry but I'm unable to reproduce your problem, for my all works fine:

Order by DESC:

PHP Code:
public function ordered () {
   $query $this->builder()
   echo $query->getCompiledSelect(false);

   return $query->get()->getResult();

[Image: JxnAxGm.png]
[Image: NaVPJ9f.png]

Order by ASC
PHP Code:
public function ordered () {
   $query $this->builder()
   echo $query->getCompiledSelect(false);

   return $query->get()->getResult();

[Image: V0WM8kT.png]
[Image: w1QvsDU.png]

Messages In This Thread
orderBy not sorting results - by pkMyt1 - 10-05-2018, 07:54 PM
RE: orderBy not sorting results - by unodepiera - 10-05-2018, 11:02 PM
RE: orderBy not sorting results - by pkMyt1 - 10-06-2018, 07:27 AM

Theme © iAndrew 2016 - Forum software by © MyBB