• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
return number of rows

#1
[eluser]rochellecanale[/eluser]
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

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

my model function

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

my controller

Code:
public function viewMemberSales(){
      $data['memsales'] = $this->sales_model->getAllMembershipSales();
      $data['totalsales'] = $this->sales_model->countTotalSalesRecord();
      $this->load->view('sites/membershipsales',$data);
}

===========================================================================================
it results to Total Records: 1

#2
[eluser]rochellecanale[/eluser]
ok i found out the answer i must use the function count_all_results() and thats all.

#3
[eluser]john_j[/eluser]
what it returns is correct, it has to return '1' because there is only one row.

Do something like this to get the count:
Code:
$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;
}


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.