• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Number of results is wrong

#1
Hi,
I am a newbie with codeigniter 4.

I have a table with 3 entries each entry has a unique uniid. With my query I want to get the one entry with the corresponding uniid. This works but when I want to check if the result of the query has found 1 entry it doesn't work anymore, because the function countAll() always returns 3 instead of 1.

Can someone help me what I am doing wrong?


Thank you....


Code:
public function verifyUniid($id) {
  $builder = $this->db->table("users");
  $builder->select('activation_date,uniid,status');
  $builder->where('uniid',$id);
  $result=$builder->get();
  if($builder->countAll()==1){

    return $result->getRow();
  } else {
    return $builder->countAll();
  }

}
Reply

#2
This is working as intended. countAll() returns the total number of rows in a table.  Use countAllResults() to get the number or rows returned by a query.  The documentation can be reviewed here: https://codeigniter4.github.io/userguide...ng-results.
Reply

#3
Thanks
Reply

#4
Be careful: return $result->getRow(); returns one single row. Instead
return $result->getResult(); turns all your list
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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