我正在尝试使用 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/