• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Order By Time Not Working

#1
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]
Reply

#2
Look at this maybe it will help you.

MySQL EXTRACT() Function

You can use this with order by also...
What did you Try? What did you Get? What did you Expect?

Joined the CodeIgniter Community in 2009.          ( Skype: insitfx )
Reply

#3
(02-13-2018, 05: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
Reply

#4
You should use DATETIME DATE and TIME fields for storing date and time.
What did you Try? What did you Get? What did you Expect?

Joined the CodeIgniter Community in 2009.          ( Skype: insitfx )
Reply

#5
(02-13-2018, 09: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
Reply

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

For the Time you can use this:

MySQL TIME_FORMAT() Function
What did you Try? What did you Get? What did you Expect?

Joined the CodeIgniter Community in 2009.          ( Skype: insitfx )
Reply

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

#8
If you read the posts you would have read that he changed it to a TIME field.
What did you Try? What did you Get? What did you Expect?

Joined the CodeIgniter Community in 2009.          ( Skype: insitfx )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
2 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2018 MyBB Group.