根据电子邮件ID计算蛋糕php中的行数

时间:2012-04-01 12:31:01

标签: php cakephp cakephp-1.3

当我在php中没有计算行时我确实喜欢那个

   $sql=mysql_query("select * from users where username='$email'") or die("select error".mysql_query());

   $no_rows=mysql_num_rows($sql);

但我不知道如何在蛋糕php中做到这一点,我的数据来自

[User] => Array
    (
        [first_name] => arjun
        [last_name] => tyagi
        [username] => arjun@gmail.com
        [phone_no] => 9569908024
        [mobile_no] => 9569908024
        [state_id] => 2
        [location_id] => 15
        [password] => cffa41a028807034b54b5849d5f4d3ca7532e701
        [confirm_password] => 12345
    )

3 个答案:

答案 0 :(得分:12)

$totalUsers = $this->User->find('count', array('conditions'=>array('User.email' => $email)));

但实际上这有很好的记录: http://book.cakephp.org/2.0/en/models/retrieving-your-data.html

答案 1 :(得分:0)

要获取行数(有条件),您应该查找find('count') function

答案 2 :(得分:0)

对于 CakePhp 3.x ,获取结果计数, 创建查询对象后,可以使用count()方法获取该查询的结果计数:

// In a controller
$query = $this->users->find('all', [
   'conditions' => ['email' => 'youremail@domain.com']
]);
$number = $query->count();