Welcome Guest, Not a member yet? Register   Sign In
[Solved] ORDER_BY DATE Not Working Properly
#1

(This post was last modified: 09-24-2016, 09:03 PM by wolfgang1983.)

I on my table I need to be able to get the latest topics by date

[Image: 2wFSqUEfgJr7.png]



[Image: 2wFUTe4Vblm3.png]




For some reason will only get the 2016-09-26 date as latest but should get 2016-09-27 these are fake dates just for testing

Question: How can I properly use order_by with my date_added column.  If unable should I use a timestamp?


PHP Code:
public function get_latest_threads($category_id) {
 
 $this->db->select('fh.*, u.username, CONCAT(fh.topics, '.', fh.replys) AS topics');
 
 $this->db->from($this->db->dbprefix 'forum_threads fh''left');
 
 $this->db->join($this->db->dbprefix 'user u''u.user_id = fh.thread_id''inner');
 
 $this->db->order_by('fh.date_added''desc');
 
 $this->db->where('fh.category_id'$category_id);
 
 $this->db->limit(1);
 
 $query $this->db->get();
 
 return $query->result_array();

There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#2

Found problem

Was this



PHP Code:
$this->db->join($this->db->dbprefix 'user u''u.user_id = fh.thread_id''left'); 


I now changed to this


PHP Code:
$this->db->join($this->db->dbprefix 'user u''u.user_id = fh.user_id''left'); 


Works some reason now.
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB