Count of group by in CodeIgniter -


i wan display first 9 places have highest number of reservations. must have count of $this->db->group_by('t.id_pl') , order of counted number.

i've managed don't understand should put count :

function select_pop () {     $this->db->select( 's.place place, s.price price, s.title title' );                 $this->db->from('places s');      $this->db->join('reservations t', 't.id_pl= s.place', 'inner');            $this->db->group_by('t.id_pl');     $this->db->order_by('');      $this->db->limit(9);         $result = $this->db->get();     return $result;  }   

any suggestions?

you can add count in select statement below-

$this->db->select('count(t.id_pl) reservation_count,s.place place, s.price price, s.title title'); 

then order can use like-

$this->db->order_by('reservation_count','desc'); 

i hope you..


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -