• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
num_rows() from CI3 on CI4

#1
Hi again,
I have been having problems in verifying if a database record exists by selecting it and returning his row, and then proceed to count the number of rows deciding true(if number of rows bigger than 0) and false(else)

Can you give me a hint, I feel like I'm missing something really simple, and I am typing unnecessary code.
Thank you, the your time.

PHP Code:
public static function verify_user_by_cod($cod)
  {

    $db db_connect();
    $builder $db->table('users');

    $builder->select('*');
    $builder->where('cod_user'$cod);
    $query $builder->get();

    
    
if (count($query->getResultArray()) > 0) {
      return true;
    } else {
      return false;
    }
  
Reply

#2
Hi you have a countAllResults() function you can use instead. You can ignore select() and get() and only use table(), where() and countAllResults().
Reply

#3
(04-22-2020, 10:15 AM)jreklund Wrote: Hi you have a countAllResults() function you can use instead. You can ignore select() and get() and only use table(), where() and countAllResults().

Thank very much jreklund, i did spend time looking around in the documentation...ehehe seems i lack focus.

The code looks like below and works without a problem, thank you.
PHP Code:
    $db db_connect();
    $builder $db->table('users');
    $builder->where('cod_user'$cod);
    
    
if ($builder->countAllResults() > 0) {
      return true;
    } else {
      return false;
    
Reply

#4
Great that it worked out for you, and thanks for providing the finished code. It will help others develop their applications in the future.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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