Welcome Guest, Not a member yet? Register   Sign In
Order by primary key is possible?
#1

[eluser]Rubiz'[/eluser]
Hi all..

I think its not possible, but I have a database that has several names of primary keys, exemple promotions_id, news_id, and some with only "id" name.

I use always $this->db->get(); to retrieve this information, but now I see I need to use $this->db->order_by('id', 'desc');, but id registers are with different names, so, I would like to know if is possible make a "order by primary key" or something like that...

Is it?
#2

[eluser]Rubiz'[/eluser]
Well, I always discover that if I had red a little bit more the user guide I had discovered the answer myself:

Code:
$fields = $this->db->field_data( $table );
        $pk     = $fields[0]->name;
        $this->db->order_by( $pk, 'desc');
        $query  = $this->db->get($table);
        return $query->result();




Theme © iAndrew 2016 - Forum software by © MyBB