php - 从 cakephp 中的另一个表获取表的计数

标签 php mysql cakephp-3.0

我正在尝试使用 cakephp3 从另一个表中获取表的计数,但出现错误

Error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') AS Transactions__COUNT() FROM transactions Transactions LEFT JOIN transactio' at line 1

我不知道我的代码有什么问题!!

这是我的 Controller :

  $data = $this->Transactions->find(
        'all', 
        array(
            'fields' => array('COUNT(*)'),
            'group' => array('transactions_type_id'),
            'contain' => array('TransactionsTypes')
             )                );

这是我的 ctp:

 <?php 
                        foreach ($data as $transactionsType) {

                            ?>
             <li>
                <p class="clearfix"><i class="icon-radio-checked text-info"></i><b><?php echo $transactionsType['title'] ?> </b><span>210</span>
                </p>
                <div class="progress progress-md">
                    <div class="progress-bar progress-bar-info" role="progressbar" aria-valuenow="8" aria-valuemin="0" aria-valuemax="100" style="width: 8%"><span class="sr-only">10% Complete (success)</span>
                    </div>
                </div>
            </li>
             <?php }
                        ?>

最佳答案

你可以使用 count() 函数。

$count=TableRegistry::get('Transactions')
    ->find()
    ->contain('TransactionsTypes')
    ->group('Transactions.transactions_type_id')
    ->count(); 

关于php - 从 cakephp 中的另一个表获取表的计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43655027/

相关文章:

java - 为 DriverManager.getConnection 获取 java.lang.NumberFormatException

php - CakePHP 3.0 - 在实体中使用 MySQL 函数

缺少 PHP DOM 文件

PHP - 深入数据并使用循环进行循环

php - MySQL 语法 :You have an error in your SQL syntax…

php - 使用服务器发送事件在 cakephp 3 中实现数据库插入进度条

mysql - 如何直接从 MySQL 解密 Cakephp3 加密数据?

php - 在没有仅索引表的情况下跟踪开/关

python - 进行条件 django 查询的更好方法

php - Laravel 5.7 - 将两列相乘并添加到最终总和