Welcome Guest, Not a member yet? Register   Sign In
counting total problem
#1

[eluser]Bigil Michael[/eluser]
code i used to calculate the count is given below
Code:
$count=0;
  $this->db->select('COUNT(rr.id) AS total');
     $this->db->from('rooms_reservation AS rr');
     $this->db->join('rooms AS r', 'r.id = rr.rooms_id');
  $this->db->where('rr.status','1');
  $this->db->group_by(array("rr.category_id", "rr.checkin_date", "rr.checkout_date", "rr.reservation_date", "rr.name", "rr.email", "rr.num_rooms"));
  $result_total = $this->db->get();
  if($result_total->num_rows()>0){
   $row = $result_total->row();
   $count = $row->total;
  }
  return $count;
every time it prints count 1.
i print the query and run on mysql

Code:
SELECT COUNT(rr.id) AS total FROM (`rooms_reservation` AS rr) JOIN `rooms` AS r ON `r`.`id` = `rr`.`rooms_id` WHERE `rr`.`status` = '1' GROUP BY `rr`.`category_id`, `rr`.`checkin_date`, `rr`.`checkout_date`, `rr`.`reservation_date`, `rr`.`name`, `rr`.`email`, `rr`.`num_rooms`

result is like this
total
1
1
2
2
2
2
.
.
.
like this
if i remove group by count prints correctly. but cant remove group by.
can any one help me to solve this problem
#2

[eluser]Bigil Michael[/eluser]
can any one help me????
#3

[eluser]Bigil Michael[/eluser]
any one know how to calculate the sum of these counts.
#4

[eluser]InsiteFX[/eluser]
Try:
Code:
$count = count($row->total);
#5

[eluser]Bigil Michael[/eluser]
thanks for yor reply.
#6

[eluser]Bigil Michael[/eluser]
solved my problem like this

controller
Code:
$tot = $this->Reservations_model->get_enq_total();
$tk = '';
foreach($tot as $row) {
$total = $tk++;
}
$config['total_rows'] = $total+1;

model

Code:
function get_enq_total()
    {
  $count=0;
  $this->db->select('COUNT(rr.id) AS total');
     $this->db->from('rooms_reservation AS rr');
     $this->db->join('rooms AS r', 'r.id = rr.rooms_id');
  $this->db->where('rr.status','0');
  $this->db->group_by(array("rr.category_id", "rr.checkin_date", "rr.checkout_date", "rr.reservation_date", "rr.name", "rr.email", "rr.num_rooms"));
  $result_total = $this->db->get();
  return $result_total->result();
    }





Theme © iAndrew 2016 - Forum software by © MyBB