Welcome Guest, Not a member yet? Register   Sign In
return number of rows

hey guys i just want to ask what can i do to return the number of rows in my mysql tables?
ive got an error when i used $query->num_rows(); not actually an error but it returned to '1'? here's my code hope you can help me.

my view

   <td>&lt;?php echo "Total Records: ".$totalsales ?&gt;</td>

my model function

public function countTotalSalesRecord(){
     $query = $this->db->query("SELECT COUNT(*) FROM tbl_membership_sales");
     return $query;

my controller

public function viewMemberSales(){
      $data['memsales'] = $this->sales_model->getAllMembershipSales();
      $data['totalsales'] = $this->sales_model->countTotalSalesRecord();

it results to Total Records: 1

ok i found out the answer i must use the function count_all_results() and thats all.

what it returns is correct, it has to return '1' because there is only one row.

Do something like this to get the count:
$result = $this->db->query('select count(*) as total_count from some_table');
if ($result != false)
   $my_count = $result->row();
   echo 'Total Count = '.$my_count->total_count;

Theme © iAndrew 2016 - Forum software by © MyBB