CodeIgniter Forums

Full Version: Order By Time Not Working
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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]
Look at this maybe it will help you.

MySQL EXTRACT() Function

You can use this with order by also...
(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
You should use DATETIME DATE and TIME fields for storing date and time.
(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
Career should be either a varchar(length) or text.

For the Time you can use this:

MySQL TIME_FORMAT() Function
Would be problem in field selection, Might be You have choosed VARCHAR Field insted of DATETIME.
If you read the posts you would have read that he changed it to a TIME field.