CodeIgniter Forums
Order By Time Not Working - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: Order By Time Not Working (/thread-70051.html)



Order By Time Not Working - wolfgang1983 - 02-13-2018

Hi, I am working on my project but for some reason my order_by('time', 'asc') is not sorting out my list correct

As you can see number 4 and 8 should be closer together but is not I am not sure if its because the way I have my database column set up if it is please let me know what it should be.

How can I make sure is displayed by correct time or career?


[Image: 3rYeAy1qQHON.png]




PHP Code:
public function list() {
 
       $data['greyhounds'] = array();

 
       $this->db->where('track'$this->uri->segment(3));
 
       $this->db->where('race_number'$this->uri->segment(4));
 
       $this->db->order_by('time''desc');
 
       $query $this->db->get('greyhounds');

 
       foreach ($query->result_array() as $result) {
 
           $data['greyhounds'][] = array(
 
               'track' => $result['track'],
 
               'race_number' => $result['race_number'],
 
               'trap' => $result['trap'],
 
               'time' => $result['time'],
 
               'form' => $result['form'],
 
               'price' => $result['price'],
 
               'career' => $result['career']
 
           );
 
       }

 
       $this->load->view('header');
 
       $this->load->view('list'$data);
 
       $this->load->view('footer');  



Here is a copy of my database

[Image: 3rYexMRbGtB7.png]


RE: Order By Time Not Working - InsiteFX - 02-13-2018

Look at this maybe it will help you.

MySQL EXTRACT() Function

You can use this with order by also...


RE: Order By Time Not Working - wolfgang1983 - 02-13-2018

(02-13-2018, 04:26 AM)InsiteFX Wrote: Look at this maybe it will help you.

MySQL EXTRACT() Function

You can use this with order by also...

Thanks I changed couple things in data base I had it like int() in column changed column to text now time in correct order


RE: Order By Time Not Working - InsiteFX - 02-13-2018

You should use DATETIME DATE and TIME fields for storing date and time.


RE: Order By Time Not Working - wolfgang1983 - 02-13-2018

(02-13-2018, 08:15 AM)InsiteFX Wrote: You should use DATETIME DATE and TIME fields for storing date and time.

What do you think the career should be for the database column? I changed the time column to TIME how ever it removed 

30.29 seconds it removed the .29 now only shows 00:00:30


RE: Order By Time Not Working - InsiteFX - 02-14-2018

Career should be either a varchar(length) or text.

For the Time you can use this:

MySQL TIME_FORMAT() Function


RE: Order By Time Not Working - Agileinfoways - 02-15-2018

Would be problem in field selection, Might be You have choosed VARCHAR Field insted of DATETIME.


RE: Order By Time Not Working - InsiteFX - 02-15-2018

If you read the posts you would have read that he changed it to a TIME field.