CodeIgniter Forums
Count Records WITH AND WITHOUT LIMITATION... using Codiegniter Standard... - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Count Records WITH AND WITHOUT LIMITATION... using Codiegniter Standard... (/showthread.php?tid=69269)



Count Records WITH AND WITHOUT LIMITATION... using Codiegniter Standard... - ganeshamoorthi - 10-30-2017

Hi,


$this->db->select('*');
$this->db->from('payment_transaction');
if ($searchFilter<>"") {
$this->db->where("paymentMethod",$searchFilter);
$this->db->or_where("paymentId",$searchFilter);
$this->db->or_where("paymentState",$searchFilter);
}
////////////////////////////////// HERE I NEED, THE COUNT RECRODS IN THAT TABLE, WITHOUT LIMITATION.....
if ($startRec==0) {
$this->db->limit($limit);
}  else {
$this->db->limit($limit,$startRec);
}
$transcationQuery=$this->db->get();
////////////////////////////////// HERE I NEED, FETCH RECORDS WITH LIMITATION.....

Note: Please don't repeate the code....


   But this case, not working, Please solve this problem as soon as possible...


RE: Count Records WITH AND WITHOUT LIMITATION... using Codiegniter Standard... - InsiteFX - 10-31-2017

See the MySQL Documentation on the COUNT()


RE: Count Records WITH AND WITHOUT LIMITATION... using Codiegniter Standard... - dave friend - 10-31-2017

Query Builder Caching provides one solution.

PHP Code:
$this->db
  
->start_cache()
 
 ->select('*')
 
 ->from('payment_transaction');
if(!empty(
$searchFilter))
{
 
   $this->db
      
->where("paymentMethod"$searchFilter)
 
     ->or_where("paymentId"$searchFilter)
 
     ->or_where("paymentState"$searchFilter);
}

//count the reccords the above returns
$total_records $this->db->get()->num_rows();

// It is assumed you are using $total_records to determine $startRec 
// your logic should allow the value to be zero if needed. Then...
$transcationQuery $this->db
  
->limit($limit$startRec)
 
 ->get();
$this->db
  
->stop_cache()
 
 ->flush_cache(); 

I'm a fan of Method Chaining as you can see by the way it is used for calls to $this->db.


RE: Count Records WITH AND WITHOUT LIMITATION... using Codiegniter Standard... - yogadiprasetyo - 11-03-2017

Please check your MySQL on the count()