php - codeigniter active record query using two order by -


i'm new in ci, , have question..

my normal sql is:

$tb1 = 'se_avg'; $tb2 = 'se_school';  $sql_top = "(select * $tb1 ,$tb2 $tb1.sid = $tb2.sid , gid = '$gid' , avg_mark > $s_mark  , $tb1.year = '2014' order avg_mark asc limit 0 , 20) order vg_mark desc"; 

i wanna rewrite in ci active record.

but have no idea put order outside sql:

$sql_top = "(select * $tb1 ,$tb2 $tb1.sid = $tb2.sid , gid = '$gid' , avg_mark > $s_mark  , $tb1.year = '2014' order avg_mark asc limit 0 , 20) 

now, ci active record is:

$tb1 = 'se_avg'; $tb2 = 'se_school';  $sql_top = $this->db            ->select('*')            ->from($tb1)            ->join($tb2, "$tb1.sid = $tb2.sid", 'left')            ->where('gid', $gid)            ->where('avg_mark >', $s_mark)            ->where("$tb1.year", '2014')            ->order_by("avg_mark", 'asc')            ->limit(20, 0);  $query = $this->db->get(); 

where can add order_by(("avg_mark", 'desc')?

i've try put after limit, wrong data...

maybe there's way?

thanks!

  • make following changes in query , desired result
  • change table contains avg_mark

->order_by('$tb1.avg_mark', 'desc')


Comments

Popular posts from this blog

.htaccess - htaccess convert request to clean url and add slash at the end of the url -

C# random value from dictionary and tuple -

algorithm - Testing tetrahedron-triangle intersection -