简体   繁体   中英

Get New Users from Database CodeIgniter

I have in database table with users, where is user register day in unix timestamp. I write this code, but it's not working. What do you think about that?

public function getUsersAmount($amount)
        {
            $time = time();
            $registers = 0;
            # $amountdays = u_reg_date - $time < -86400 * $amount

            $this->db->select('*');
            $this->db->from('users');
            $query = $this->db->get();

            for($x = 0; $x <= $query->num_rows(); $x++)
            {
                if($result['u_reg_date'] - $time < (-86400 * $amount))
                {
                    $registers++;
                }
            }

            return $registers;
        }
`

You could do the last part with this:

if ($query->num_rows() > 0) {       
  foreach ($query->result_array() as $row) {
    if($row->u_reg_date < $time - (86400 * $amount)) {
      $registers++;
    }
  }
}

But you should do this with a where query and just return the rows count;

$this->db->select('*');
$this->db->from('users');
$this->db->where('u_reg_date < ', time() - (86400 * $amount));
$query = $this->db->get();
return $query->num_rows();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM