【问题标题】:count no of rows in cake php base on email id根据电子邮件 ID 计算蛋糕 php 中的行数
【发布时间】:2012-04-15 09:40:02
【问题描述】:

当我计算 php 中的行数时,我确实喜欢这样

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

   $no_rows=mysql_num_rows($sql);

但我不知道如何在 cake 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
    )

【问题讨论】:

    标签: php cakephp cakephp-1.3


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:
      $totalUsers = $this->User->find('count', array('conditions'=>array('User.email' => $email)));
      

      但这实际上是有据可查的: http://book.cakephp.org/2.0/en/models/retrieving-your-data.html

      【讨论】:

        【解决方案3】:

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

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2013-09-20
          • 1970-01-01
          • 1970-01-01
          • 2013-02-01
          • 1970-01-01
          • 2013-12-20
          • 1970-01-01
          • 2012-06-02
          相关资源
          最近更新 更多