I am new in codeigniter, I want to count all rows from database table but the query dose not retrieve the exact total of rows. Here is Model
public function countRow(){
$query = $this->db->query("SELECT *,count(id) AS num_of_time FROM home");
// print_r($query->result());
return $query->result();
}
and this is the controller
public function countTotalrow(){
$data['query'] = $this->home_model->countRow();
}
this is the view
foreach ($num_of_time as $row){
<span><?php print_r($row->id);?></span>
You could use the helper function $query->num_rows()
It returns the number of rows returned by the query. You can use like this:
$query = $this->db->query('SELECT * FROM my_table');
echo $query->num_rows();
Use this code:
$this->db->where(['id'=>2])->from("table name")->count_all_results();
or
$this->db->from("table name")->count_all_results();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With